image_convert.py 981 B

1234567891011121314151617181920212223242526272829
  1. from wand.image import Image as wima
  2. from wand.color import Color
  3. import os
  4. from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor, as_completed, wait
  5. def wmf2png(old_src):
  6. """
  7. 1.将公式wmf格式转化为png图片
  8. :param old_src:
  9. :return:
  10. """
  11. with wima(filename=old_src, resolution=300, background=Color('rgba( 0, 0, 0, 0.0)'), format='png') as img:
  12. # newfilename = os.path.join(base_dir, fname[:-3]+"png")
  13. # img.convert()
  14. img.save(filename=os.path.splitext(old_src)[0] + ".png")
  15. def svg2png(old_src):
  16. """svg转png"""
  17. with wima(filename=old_src, resolution=400, background=Color('rgba( 0, 0, 0, 0.0)'), format='png') as img:
  18. newfilename = os.path.splitext(old_src)[0] + ".png"
  19. img.save(filename=newfilename)
  20. return img.size, newfilename
  21. if __name__ == '__main__':
  22. fn = r"F:\zwj\Text_Structure\img_folder\0213441313131\svg_mjmath\MJMATH-1652453454103257.svg"
  23. svg2png(fn)