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'
    for i in range(numberOfPages(path)):

    Thank you!!!

  • hello @eduairet,

    you can use the pageNumber argument in image or imageSize 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)


  • @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)
    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 an ImageObject 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)
    image(img, (0, 0))


  • @gferreira Awesome! Thanks so much!

Log in to reply