Skip to content

pillow python

Pillow is a popular Python library for working with images. It provides a wide range of image processing capabilities, including opening, manipulating, and saving various image file formats. Pillow is an open-source library and is the successor to the Python Imaging Library (PIL).

Here are some common tasks you can perform using Pillow:

  1. Opening an image:
   from PIL import Image

   image = Image.open("example.jpg")
  1. Displaying an image:
   image.show()
  1. Resizing an image:
   new_size = (width, height)
   resized_image = image.resize(new_size)
  1. Rotating an image:
   rotated_image = image.rotate(90)
  1. Saving an image:
   image.save("output.jpg")
  1. Converting between different image modes (e.g., RGB to grayscale):
   grayscale_image = image.convert("L")
  1. Cropping an image:
   box = (left, upper, right, lower)
   cropped_image = image.crop(box)
  1. Adding text to an image:
   from PIL import ImageDraw, ImageFont

   draw = ImageDraw.Draw(image)
   font = ImageFont.truetype("arial.ttf", size=36)
   draw.text((x, y), "Hello, Pillow!", fill="red", font=font)

Pillow provides extensive documentation and is widely used in various image processing applications in Python. You can install it using pip:

pip install Pillow

Make sure to refer to the Pillow documentation for more details and examples: https://pillow.readthedocs.io/en/stable/index.html

Leave a Reply

Your email address will not be published. Required fields are marked *

error

Enjoy this blog? Please spread the word :)