rename fix

This commit is contained in:
2024-04-30 22:46:22 -06:00
parent cc485162f1
commit b1b7563c46
3 changed files with 115 additions and 108 deletions

View File

@@ -1,108 +0,0 @@
`Pillow` (PIL Fork) is an open-source Python Imaging Library that adds image processing capabilities to your Python interpreter. This library supports opening, manipulating, and saving many different image file formats and is designed to be powerful yet simple and easy to use. Pillow is a continuation of the original PIL library, actively developed and supported, making it essential for tasks involving images. Here's a concise reference guide for common use cases with `Pillow`:
# `Pillow` Reference Guide
## Installation
```
pip install Pillow
```
## Basic Operations
### Opening and Saving Images
```python
from PIL import Image
# Open an image file
img = Image.open('path/to/image.jpg')
# Save the image in a different format
img.save('path/to/new_image.png')
```
### Displaying Images
```python
# Display the image
img.show()
```
## Image Transformations
### Resizing Images
```python
# Resize the image
resized_img = img.resize((new_width, new_height))
# Maintain aspect ratio
aspect_ratio = img.width / img.height
new_width = 100
resized_img = img.resize((new_width, int(new_width / aspect_ratio)))
```
### Cropping Images
```python
# Crop the image
left, top, right, bottom = 100, 100, 400, 400
cropped_img = img.crop((left, top, right, bottom))
```
### Rotating and Flipping Images
```python
# Rotate the image
rotated_img = img.rotate(90)
# Flip the image
flipped_img = img.transpose(Image.FLIP_LEFT_RIGHT)
```
### Applying Filters
```python
from PIL import ImageFilter
# Apply a built-in filter
blurred_img = img.filter(ImageFilter.BLUR)
```
## Advanced Operations
### Working with Colors
```python
# Convert to grayscale
gray_img = img.convert('L')
# Enhancing images
from PIL import ImageEnhance
enhancer = ImageEnhance.Contrast(img)
enhanced_img = enhancer.enhance(factor) # factor > 1 for more contrast, < 1 for less
```
### Drawing on Images
```python
from PIL import ImageDraw
draw = ImageDraw.Draw(img)
draw.line((0, 0) + img.size, fill=128)
draw.line((0, img.size[1], img.size[0], 0), fill=128)
# Save the modified image
img.save('path/to/drawn_image.jpg')
```
### Reading and Modifying EXIF Data
```python
exif_data = img._getexif()
# Note: EXIF data handling can vary; consider using the 'exif' or 'piexif' libraries for complex EXIF manipulation.
```
### Working with Thumbnails
```python
# Generate a thumbnail
img.thumbnail((thumbnail_width, thumbnail_height))
img.save('path/to/thumbnail.jpg')
```
`Pillow` provides a comprehensive suite of image processing tools, from basic operations like opening and saving images to more complex manipulations and effects. This guide covers foundational image manipulation techniques, but `Pillow`'s capabilities extend to a wide range of other features, including image filtering, enhancing, and more, catering to nearly any image processing task.
Pillow's ease of use and extensive functionality make it an excellent choice for image processing in Python, suitable for tasks ranging from simple script-based image modifications to complex, high-performance web applications handling image content.

View File

@@ -0,0 +1,115 @@
Let's focus on `Pillow` (PIL Fork), an extensive library used for opening, manipulating, and saving many different image file formats in Python. It's a continuation and an extension of the original Python Imaging Library (PIL) and is designed to be user-friendly and efficient for processing images.
### Pillow (PIL Fork) Complete Guide
#### Installation
```sh
pip install Pillow
```
### Basic Operations
#### Opening and Saving Images
```python
from PIL import Image
# Open an image
img = Image.open("path/to/image.jpg")
# Save the image in a different format
img.save("path/to/new_image.png")
```
#### Displaying Images
```python
img.show()
```
### Image Manipulation
#### Cropping Images
```python
# Define the box to crop (left, upper, right, lower)
box = (100, 100, 400, 400)
cropped_img = img.crop(box)
cropped_img.show()
```
#### Resizing Images
```python
# Resize the image to a new resolution
new_size = (300, 300)
resized_img = img.resize(new_size)
resized_img.show()
```
#### Rotating and Flipping Images
```python
# Rotate the image by 90 degrees
rotated_img = img.rotate(90)
rotated_img.show()
# Flip the image left to right
flipped_img = img.transpose(Image.FLIP_LEFT_RIGHT)
flipped_img.show()
```
#### Color Transforms
```python
# Convert to grayscale
gray_img = img.convert('L')
gray_img.show()
```
### Image Enhancements
Pillow provides the `ImageEnhance` module for adjusting color, brightness, contrast, and sharpness.
```python
from PIL import ImageEnhance
# Enhance the brightness
enhancer = ImageEnhance.Brightness(img)
bright_img = enhancer.enhance(2.0) # Increase brightness
bright_img.show()
# Enhance the contrast
enhancer = ImageEnhance.Contrast(img)
contrast_img = enhancer.enhance(2.0) # Increase contrast
contrast_img.show()
```
### Drawing on Images
Pillow allows you to draw on images directly using the `ImageDraw` module.
```python
from PIL import ImageDraw
draw = ImageDraw.Draw(img)
draw.line((0, 0) + img.size, fill=128)
draw.line((0, img.size[1], img.size[0], 0), fill=128)
```
### Working with Text
You can also use Pillow to add text to images.
```python
from PIL import ImageFont
draw.text((10, 25), "Hello World", fill="black")
# Using a TTF font
font = ImageFont.truetype("path/to/font.ttf", 15)
draw.text((10, 50), "Hello with font", font=font, fill="black")
```
### Potential Use Cases
- **Automating Image Editing**: Batch processing images for web optimization, creating thumbnails, or applying watermarks.
- **Data Visualization**: Generating dynamic images or charts for web or print.
- **Content Generation**: Creating images for social media posts, website banners, or marketing materials programmatically.
- **Machine Learning Preprocessing**: Preparing image datasets for training, including resizing, normalization, and augmentation.
Pillow's extensive set of features makes it an essential library for any project that involves image processing in Python. Whether you're developing a web application that handles user-uploaded images, creating graphics dynamically, or preprocessing data for machine learning models, Pillow provides the tools necessary to accomplish these tasks efficiently and effectively.