- Python Pillow Tutorial
- Python Pillow - Home
- Python Pillow - Overview
- Python Pillow - Environment Setup
- Basic Image Operations
- Python Pillow - Working with Images
- Python Pillow - Resizing an Image
- Python Pillow - Flip and Rotate Images
- Python Pillow - Cropping an Image
- Python Pillow - Adding Borders to Images
- Python Pillow - Identifying Image Files
- Python Pillow - Merging Images
- Python Pillow - Cutting and Pasting Images
- Python Pillow - Rolling an Image
- Python Pillow - Writing text on image
- Python Pillow - ImageDraw Module
- Python Pillow - Concatenating two Images
- Python Pillow - Creating Thumbnails
- Python Pillow - Creating a Watermark
- Python Pillow - Image Sequences
- Python Pillow Color Conversions
- Python Pillow - Colors on an Image
- Python Pillow - Creating Images With Colors
- Python Pillow - Converting Color String to RGB Color Values
- Python Pillow - Converting Color String to Grayscale Values
- Python Pillow - Change the Color by Changing the Pixel Values
- Image Manipulation
- Python Pillow - Reducing Noise
- Python Pillow - Changing Image Modes
- Python Pillow - Compositing Images
- Python Pillow - Working with Alpha Channels
- Python Pillow - Applying Perspective Transforms
- Image Filtering
- Python Pillow - Adding Filters to an Image
- Python Pillow - Convolution Filters
- Python Pillow - Blur an Image
- Python Pillow - Edge Detection
- Python Pillow - Embossing Images
- Python Pillow - Enhancing Edges
- Python Pillow - Unsharp Mask Filter
- Image Enhancement and Correction
- Python Pillow - Enhancing Contrast
- Python Pillow - Enhancing Sharpness
- Python Pillow - Enhancing Color
- Python Pillow - Correcting Color Balance
- Python Pillow - Removing Noise
- Image Analysis
- Python Pillow - Extracting Image Metadata
- Python Pillow - Identifying Colors
- Advanced Topics
- Python Pillow - Creating Animated GIFs
- Python Pillow - Batch Processing Images
- Python Pillow - Converting Image File Formats
- Python Pillow - Adding Padding to an Image
- Python Pillow - Color Inversion
- Python Pillow - M L with Numpy
- Python Pillow with Tkinter BitmapImage and PhotoImage objects
- Image Module
- Python Pillow - Image Blending
- Python Pillow Useful Resources
- Python Pillow - Quick Guide
- Python Pillow - Function Reference
- Python Pillow - Useful Resources
- Python Pillow - Discussion
Python Pillow - ImageChops.offset() Function
The PIL.ImageChops.offset function returns a copy of the input image where the data has been offset by the specified horizontal and vertical distances. The data wraps around the edges, and if the vertical offset (yoffset) is omitted, it is assumed to be equal to the horizontal offset (xoffset). The function takes the following parameters −
Syntax
Following is the syntax of the function −
PIL.ImageChops.offset(image, xoffset, yoffset=None)
Parameters
Here are the details of this function parameters −
image − Input image.
xoffset − The horizontal distance by which the data is offset.
yoffset − The vertical distance by which the data is offset. If omitted, both horizontal and vertical distances are set to the same value.
Return Value
The function returns an Image type, representing the resulting image after applying the offset.
Examples
Example 1
Here is an example Offset an image by a given horizontal distance only.
from PIL import Image, ImageChops # Open an Image original_image = Image.open("Images/Car_2.jpg") # Set the horizontal offset x_offset = 100 # Apply the offset to the image (y_offset defaults to x_offset) result_image = ImageChops.offset(original_image, x_offset) # Display the input and resulting image original_image.show() result_image.show()
Output
Input Image
Output Image
Example 2
The following example applies the ImageChops.offset() function to adjust the position of an Image by specified horizontal and vertical Offsets.
from PIL import Image, ImageChops # Open an Image original_image = Image.open("Images/Car_2.jpg") # Set the horizontal and vertical offsets x_offset = 100 y_offset = -50 # Apply the offset to the image result_image = ImageChops.offset(original_image, x_offset, y_offset) # Display the input and resulting image original_image.show() result_image.show()
Output
Input Image
Output Image
Example 3
The following example demonstrates the use of ImageChops.offset() to shift the image and then use Image.paste() function to fill the wrapped area with yellow color.
from PIL import Image, ImageChops # Open an Image original_image = Image.open('Images/Car_2.jpg') width, height = original_image.size # Apply the offset to the image result_image = ImageChops.offset(original_image, 10, 20) # Fill the wrapped area with the yellow color result_image.paste((255, 255, 255), (0, 0, 10, height)) result_image.paste((255, 255, 255), (0, 0, width, 20)) # Display the input and resulting image original_image.show() result_image.show()
Output
Input Image
Output Image