How to use Pillow(PIL) in Python

To use Pillow (Python Imaging Library) in Python, you can follow these steps:

  1. Install Pillow:

    • Open your terminal or command prompt.
    • Run the following command to install Pillow using pip:
      pip install pillow
      
  2. Import the Pillow module:

    • In your Python script, import the PIL module from Pillow:
      from PIL import Image
      
  3. Open and manipulate images:

    • Use the Image.open() method to open an image file:

      image = Image.open("image.jpg")
      
    • Perform various operations on the image, such as resizing, cropping, rotating, and applying filters. Here are a few examples:

      # Resize the image
      resized_image = image.resize((width, height))
      
      # Crop the image
      cropped_image = image.crop((x, y, x + width, y + height))
      
      # Rotate the image
      rotated_image = image.rotate(angle)
      
      # Apply a filter
      filtered_image = image.filter(ImageFilter.BLUR)
      
    • Save the modified image to a file:

      resized_image.save("resized_image.jpg")
      
  4. Display the image:

    • To display the image, you can use the show() method:

      image.show()
      
    • This will open the image using the default image viewer on your system.

These are just a few examples of what you can do with Pillow. It provides a wide range of image processing capabilities, including image manipulation, format conversion, and more. You can refer to the Pillow documentation for more details and advanced usage: https://pillow.readthedocs.io/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值