The PixelPerfect
is a graphical user interface (GUI) application written in Python that allows users to perform basic image editing tasks such as opening, saving, rotating, resizing, applying filters, and enhancing images. The application is built using the tkinter
library for the GUI, and the Pillow
library for image processing.
- Python: Version 3.7 or higher.
- Libraries:
tkinter
(comes with Python).Pillow
(install usingpip install pillow
).
- Open Image: Load an image from the user's file system.
- Save Image: Save the currently edited image.
- Rotate Image: Rotate the image by 90 degrees clockwise.
- Resize Image: Change the dimensions of the image based on user input.
- Apply Filter: Apply a blur filter to the image.
- Enhance Image: Adjust the contrast of the image for better visibility.
- Sets up the main application window (
root
), including title, dimensions, and default values for the loaded image. - Calls methods to create the menu and widgets.
- Adds a File menu to the menu bar with options:
Open
: Open an image file.Save
: Save the edited image.Exit
: Exit the application.
- Creates the main canvas for displaying the image (600x400 pixels).
- Adds control buttons for browsing, rotating, resizing, applying filters, and enhancing the image.
- Allows the user to browse and select an image file using a file dialog.
- Supported formats: PNG, JPEG, BMP.
- Lets the user save the currently loaded and edited image via a file dialog.
- Supported formats: PNG, JPEG.
- Resizes the image to fit the canvas dimensions and displays it on the canvas.
- Rotates the image 90 degrees clockwise and updates the display.
- Prompts the user to enter new width and height for the image.
- Resizes the image to the specified dimensions.
- Applies a blur filter to the image using
ImageFilter.BLUR
.
- Enhances the image's contrast by a factor of 1.5 using
ImageEnhance.Contrast
.
- Purpose: Manages the GUI and image processing functionalities.
- Attributes:
root
: Main application window.image
: Loaded image as aPillow.Image
object.img_display
: Image ready for display as aPhotoImage
.canvas
: Canvas widget for displaying images.
Method | Purpose |
---|---|
__init__ |
Initializes the application, sets up the GUI components. |
create_menu |
Creates the menu bar and its options. |
create_widgets |
Creates the canvas and control buttons. |
open_image |
Opens an image file from the user's system. |
save_image |
Saves the currently loaded and edited image. |
display_image |
Displays the resized image on the canvas. |
rotate_image |
Rotates the image by 90 degrees. |
resize_image |
Resizes the image based on user input dimensions. |
apply_filter |
Applies a blur filter to the image. |
enhance_image |
Enhances the image contrast by a factor of 1.5. |
- Run the script:
python image_editor_app.py
- Use the File menu or Browse Image button to open an image.
- Perform desired operations using the buttons:
- Rotate, Resize, Apply Filter, Enhance.
- Save the image using the File > Save menu option.
- Click Browse Image and select an image file.
- Click Rotate to rotate the image.
- Click Resize and input the new width and height when prompted.
- The image is resized to the specified dimensions.
- Click Save under the File menu.
- Choose a location and file name to save the edited image.
Library | Purpose |
---|---|
tkinter |
GUI development for creating the interface. |
Pillow |
Image processing tasks such as opening, saving, resizing, filtering, and enhancing. |
- Image not displayed:
- Ensure the image file format is supported (PNG, JPEG, BMP).
- Error:
AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'
:- Use
Image.Resampling.LANCZOS
instead ofImage.ANTIALIAS
.
- Use
- Use
print
statements or a debugger to trace issues in methods likeopen_image
ordisplay_image
.
- Add more filters (e.g., sharpening, edge detection).
- Enable cropping and annotating images.
- Add a "Reset" button to revert to the original image.
This documentation provides a comprehensive guide to understanding, using, and extending the ImageEditorApp
.