Image Properties¶
- imageSize(path)¶
Return the width and height of an image. Supports pdf, jpg, png, tiff and gif file formats. NSImage objects are supported too.
print(imageSize("https://raw.githubusercontent.com/typemytype/drawbot/master/tests/data/drawBot.jpg"))
- imagePixelColor(path, (x, y))¶
Return the color r, g, b, a of an image at a specified x, y position. Supports pdf, jpg, png, tiff and gif file formats. NSImage objects are supported too.
# path to the image, from https://www.wired.com/2012/08/a1-art-0-99-vending-machines-as-art-galleries/ path = "https://raw.githubusercontent.com/typemytype/drawbot/master/tests/data/drawBot.jpg" # get the size of the image w, h = imageSize(path) # setup a variable for the font size as for the steps s = 15 # shift it up a bit translate(100, 100) # set a font with a size font("Helvetica-Bold") fontSize(s) # loop over the width of the image for x in range(0, w, s): # loop of the height of the image for y in range(0, h, s): # get the color color = imagePixelColor(path, (x, y)) if color: r, g, b, a = color # set the color fill(r, g, b, a) # draw some text text("W", (x, y))
- imageResolution(path)¶
Return the image resolution for a given image. Supports pdf, jpg, png, tiff and gif file formats. NSImage objects are supported too.
- numberOfPages(path)¶
Return the number of pages for a given pdf or (animated) gif. Return None for non compatible file types.