Python 使用魔杖保存时更改 cpt
Python change cpt on save with Wand
我有以下功能可以将 PDF 转换为图像:
from wand.image import Image as Img
with Img(filename=pdfName, resolution=self.resolution) as pic:
pic.compression_quality = self.compressionQuality
pic.background_color = Color("white")
pic.alpha_channel = 'remove'
pic.save(filename='full_' + random + '-%03d.jpg')
如果 PDF 是多页的,JPG 文件是这样的:
file-000.jpg
, file-001.jpg
我的问题是,cpt 是否可以从 1 开始?
file-001.jpg
、file-002.jpg
提前致谢
更新
另一种选择是设置 Image.scene
from wand.image import Image as Img
from wand.api import library
with Img(filename=pdfName, resolution=self.resolution) as pic.
# Move the internal iterator to first frame.
library.MagickResetIterator(pic.wand)
pic.scene = 1
pic.compression_quality = self.compressionQuality
pic.background_color = Color("white")
pic.alpha_channel = 'remove'
pic.save(filename='full_' + random + '-%03d.jpg')
原创
我唯一能想到的就是在读取之前将一个空图像放在堆栈上。
with Img(filename='NULL:') as pic:
pic.read(filename=pdfName, resolution=self.resolution)
pic.compression_quality = self.compressionQuality
pic.background_color = Color("white")
pic.alpha_channel = 'remove'
pic.save(filename='full_' + random + '-%03d.jpg')
这会放一个 file-000.jpg
,但它会是空的,您可以使用 os.remove()
快速删除它
我有以下功能可以将 PDF 转换为图像:
from wand.image import Image as Img
with Img(filename=pdfName, resolution=self.resolution) as pic:
pic.compression_quality = self.compressionQuality
pic.background_color = Color("white")
pic.alpha_channel = 'remove'
pic.save(filename='full_' + random + '-%03d.jpg')
如果 PDF 是多页的,JPG 文件是这样的:
file-000.jpg
, file-001.jpg
我的问题是,cpt 是否可以从 1 开始?
file-001.jpg
、file-002.jpg
提前致谢
更新
另一种选择是设置 Image.scene
from wand.image import Image as Img
from wand.api import library
with Img(filename=pdfName, resolution=self.resolution) as pic.
# Move the internal iterator to first frame.
library.MagickResetIterator(pic.wand)
pic.scene = 1
pic.compression_quality = self.compressionQuality
pic.background_color = Color("white")
pic.alpha_channel = 'remove'
pic.save(filename='full_' + random + '-%03d.jpg')
原创
我唯一能想到的就是在读取之前将一个空图像放在堆栈上。
with Img(filename='NULL:') as pic:
pic.read(filename=pdfName, resolution=self.resolution)
pic.compression_quality = self.compressionQuality
pic.background_color = Color("white")
pic.alpha_channel = 'remove'
pic.save(filename='full_' + random + '-%03d.jpg')
这会放一个 file-000.jpg
,但它会是空的,您可以使用 os.remove()