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 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)
    

    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 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)
        
    img.falseColor(color0=(1,0,0,1))
    image(img, (0, 0))
    

    cheers!



  • @gferreira Awesome! Thanks so much!


Log in to reply