Note - Double Click to Copy Code Contact Us!
Posts

Image Resize Application

Tech Doubility
Image Resize Application


  1. from PIL import Image
  2.  
  3. def resize_image(input_image, output_image, size):
  4. try:
  5. with Image.open(input_image) as image:
  6. # Resize the image
  7. resized_image = image.resize(size)
  8. # Save the resized image
  9. resized_image.save(output_image)
  10. print("Image resized successfully!")
  11. except IOError:
  12. print("Unable to resize image")
  13.  
  14. # Example usage
  15. input_image = "input.jpg" # Path to the input image
  16. output_image = "output.jpg" # Path to save the resized image
  17. size = (800, 600) # New size of the image (width, height)
  18.  
  19. # Call the resize_image function
  20. resize_image(input_image, output_image, size)
Make sure you have the Pillow library installed. You can install it using the following command:

Copy code

pip install pillow

In the example code above, you need to replace the input_image variable with the path to your input image file. Likewise, update the output_image variable to specify the desired path and name for the resized image file. Lastly, modify the size variable to the desired dimensions for resizing the image.

After running the code, it will load the input image, resize it to the specified size, and save the resized image to the specified output path. You can adjust the code or incorporate it into a larger application according to your needs.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.