Python 3 Wand如何从多个PDF页面制作无动画的gif [英] Python 3 Wand How to make an unanimated gif from multiple PDF pages
问题描述
我需要将具有多个页面的PDF转换为单个非动画gif,其中使用Python 3(最好是Wand)将页面比另一个页面低.我尝试使用以下代码执行此操作,但是,gif仍然是动画的,因此各个页面的行为都类似于动画的帧.
I need to convert PDFs with multiple pages to a single unanimated gif where the pages will be one below the other using Python 3 and ideally Wand. I have tried doing this with the following code, however, the gif is still animated so that individual pages behave like frames of an animation.
这是我当前的代码: (PDFfile是PDF的位置,GIFfile是我要保存非动画gif的位置)
Here is my current code: (PDFfile is the location of a PDF, GIFfile is the location that I want to save the unanimated gif)
from wand.image import Image
with Image(filename = PDFfile) as img:
Pages = []
for x in range(len(img.sequence)):
Frame = Image(image = img.sequence[x])
Pages.append(Frame)
CombinedImage = Image()
HeightToPlaceAt = 0
for Page in Pages:
CombinedImage.blank(Pages[0].width,Pages[0].height * len(Pages))
CombinedImage.composite(Page,0,HeightToPlaceAt)
HeightToPlaceAt += Page.height
CombinedImage.save(filename = GIFfile)
如何停止动画以便一次显示所有帧,是否有办法将图像展平"到一帧?
How can I stop the animation so that all the frames are visible at once, is there a way to 'flatten' the image down to one frame?
谢谢
推荐答案
有时,在假定必须存在一个您不知道的功能可以解决您的问题之前,通读for循环会有所帮助.看来我已经很难找到答案了.我修改的代码:
Sometimes it helps to just read through your for loops before presuming that there must be a functions that you don't know about that will fix your problem. Looks like I have found this out the hard way. My amended code:
with Image(filename = PDFfile) as img:
Pages = []
for x in range(len(img.sequence)):
Frame = Image(image = img.sequence[x])
Pages.append(Frame)
CombinedImage = Image()
CombinedImage.blank(Pages[0].width,Pages[0].height * len(Pages))
HeightToPlaceAt = 0
for Page in Pages:
CombinedImage.composite(Page,0,HeightToPlaceAt)
HeightToPlaceAt += Page.height
CombinedImage.save(filename = GIFfile)
这篇关于Python 3 Wand如何从多个PDF页面制作无动画的gif的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!