📜  大小 pilimage - Python (1)

📅  最后修改于: 2023-12-03 15:23:44.015000             🧑  作者: Mango

PIL Image - Python

PIL (Python Imaging Library) is a popular library for handling images in Python. With PIL, developers can manipulate images in various ways, such as cropping, resizing, transforming, and more. In this article, we'll explore how to use PIL to resize images.

Installation

To install PIL, run the following command in your terminal:

pip install Pillow
Resizing Images

Resizing images is a common task in image processing. With PIL, developers can easily resize images in Python. Let's explore how to do that.

First, let's import the necessary modules:

from PIL import Image

Next, let's open an image and resize it:

# Open the image
img = Image.open('path/to/image.jpg')

# Resize the image
new_img = img.resize((300, 300))

# Save the resized image
new_img.save('resized_image.jpg')

In the code above, we opened an image and resized it to a new size of 300x300 pixels. We then saved the resized image to a new file.

Conclusion

In this article, we've explored how to use PIL to resize images in Python. PIL is a powerful library for handling images, and it provides many tools for image processing and manipulation. If you're working with images in Python, PIL is definitely worth checking out.