image_convert.py 838 B

123456789101112131415161718192021222324
  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=200, 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