access a specific frame from a gif
-
Hi DrawBot experts!!!
Does anyone know how to access a specific frame from a gif?I'm using the numberOfPages(path) to see them and create the range of a loop but I can't find the way to make the iteration, I was thinking in something like this
path = '~/Desktop/image.gif' numberOfPages(path) for i in range(numberOfPages(path)): pass
Thank you!!!
-
hello @eduairet,
you can use the
pageNumber
argument inimage
orimageSize
to get a given frame in a multipage image (gif or pdf). important: page numbering starts at 1.see Inserting a PDF
path = '~/Desktop/image.gif' pageCount = numberOfPages(path) for pageNumber in range(1, pageCount+1): w, h = imageSize(path, pageNumber=pageNumber) newPage(w, h) image(path, (0, 0), pageNumber=pageNumber)
cheers!
-
@gferreira you rock, thanks a lot!!!!!
-
Is there a way to do this with an
ImageObject()
?I'm trying to do something similar with a pdf, and then apply some filters.
img = ImageObject(path, pageNumber= pageNumber) img.falseColor(color0=(0,0,1,1)) image(img, (0, 0))
This gives an
unexpected keyword argument 'pageNumber'
.And moving the pageNumber to the image call, has no effect. It just inserts the first page:
image(img, (0, 0), pageNumber=pageNumber)
-
hello @traviskochel,
you can use
image()
inside anImageObject
to get a specific page, and then apply the filters using the image object. like this:path = 'myFolder/myDocument.pdf' img = ImageObject() with img: w, h = imageSize(path) size(w, h) image(path, (0, 0), pageNumber=4) img.falseColor(color0=(1,0,0,1)) image(img, (0, 0))
cheers!
-
@gferreira Awesome! Thanks so much!
-
This is an old post but this might help someone looking for iteration on gifs, and maybe anyone can tell an interesting fact about it. I've been working with gifs generated via Photoshop and Media Encoder and they crash after the second frame. What has worked for me to fix this problem is to open the gif file with the Mac OS Preview app and rewrite the file, even though this solved my problem it could be great to know if you had a similar experience and how you solved it.