bembry.org
Home / Technology / Python / Notes

Python Imaging Library Reference Notes

  • The official reference is here.
  • ImageTK module
    • BitmapImage(image, foreground="color")
      Convert an image into a bitmap
    • PhotoImage(image)
      Turns any image format (jpg, png, etc.) into a Tkinter compatible image
  • Image module
    • img.open(filename)
    • img.save(outfile, format) If format omitted, bases file type on extension of filename
    • img.resize(size) size in (height, width) as a tuple
    • img.rotate(angle) rotates image counter-clockwise around the center
    • img.thumbnail(size) creates a thumbnail of the image
  • ImageEnhance module
    • NOTE: All classes in this module use the method "enhance(factor)". So code would look like:
      pic = ImageEnhance.Color(image)
      pic.enhance(1.5)
    • Color(image) 0.0 = black and white, 1.0 = original
    • Brightness(image) 0.0 = black, 1.0 = original
    • Contrast(image)0.0 = solid grey, 1.0 = original
    • Sharpness(image) 0.0 = blurred, 1.0 = original, 2.0 = sharpen
  • ImageFilter module
    • NOTE: These are predefined routines to use with the filter method of the Image class. A sample code would look like: img.filter(ImageFilter.BLUR).
    • BLUR
    • CONTOUR
    • DETAIL
    • EDGE_ENHANCE
    • EDGE_ENHANCE_MORE
    • EMBOSS
    • FIND_EDGES
    • SMOOTH
    • SMOOTH_MORE
    • SHARPEN
    • Restricted access