1234567891011121314151617181920212223242526272829 |
- from wand.image import Image as wima
- from wand.color import Color
- import os
- from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor, as_completed, wait
- def wmf2png(old_src):
- """
- 1.将公式wmf格式转化为png图片
- :param old_src:
- :return:
- """
- with wima(filename=old_src, resolution=300, background=Color('rgba( 0, 0, 0, 0.0)'), format='png') as img:
- # newfilename = os.path.join(base_dir, fname[:-3]+"png")
- # img.convert()
- img.save(filename=os.path.splitext(old_src)[0] + ".png")
- def svg2png(old_src):
- """svg转png"""
- with wima(filename=old_src, resolution=400, background=Color('rgba( 0, 0, 0, 0.0)'), format='png') as img:
- newfilename = os.path.splitext(old_src)[0] + ".png"
- img.save(filename=newfilename)
- return img.size, newfilename
- if __name__ == '__main__':
- fn = r"F:\zwj\Text_Structure\img_folder\0213441313131\svg_mjmath\MJMATH-1652453454103257.svg"
- svg2png(fn)
|