5.4.0

API Changes

APNG extension to PNG plugin

Animated Portable Network Graphics (APNG) images are not fully supported butcan be opened via the PNG plugin to get some basic info:

  1. im = Image.open("image.apng")
  2. print(im.mode) # "RGBA"
  3. print(im.size) # (245, 245)
  4. im.show() # Shows a single frame

Check for libjpeg-turbo

You can check if Pillow has been built against the libjpeg-turbo version of thelibjpeg library:

  1. from PIL import features
  2. features.check_feature("libjpeg_turbo") # True or False

Negative indexes in pixel access

When accessing individual image pixels, negative indexes are now also accepted.For example, to get or set the farthest pixel in the lower right of an image:

  1. px = im.load()
  2. print(px[-1, -1])
  3. px[-1, -1] = (0, 0, 0)

New custom TIFF tags

TIFF images can now be saved with custom integer, float and string TIFF tags:

  1. im = Image.new("RGB", (200, 100))
  2. custom = {
  3. 37000: 4,
  4. 37001: 4.2,
  5. 37002: "custom tag value",
  6. 37003: u"custom tag value",
  7. 37004: b"custom tag value",
  8. }
  9. im.save("output.tif", tiffinfo=custom)
  10.  
  11. im2 = Image.open("output.tif")
  12. print(im2.tag_v2[37000]) # 4
  13. print(im2.tag_v2[37002]) # "custom tag value"
  14. print(im2.tag_v2[37004]) # b"custom tag value"

Other Changes

ImageOps.fit

Now uses one resize operation with box parameter internallyinstead of a crop and scale operations sequence.This improves the performance and accuracy of cropping sincethe box parameter accepts float values.