1 / 7

How to Resize Image in Python

Sometimes you may need to resize image in Python. Here is how to do this using Python Image Library.#python #image <br><br>Visit https://techimbo.com/how-to-resize-image-in-python/

Download Presentation

How to Resize Image in Python

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. How to Resize Image in Python

  2. Install Python Image Library For this purpose, we will use Python Image Library (PIL). You can install it with the following command. $ pip install Pillow

  3. Create Python Script Run the following command to create a new python script $ vi test.py

  4. Add Code to Resize Image Add the following code to your python script to resize image #!/usr/bin/env python import os, sys from PIL import Image size = 128, 128 for infile in sys.argv[1:]: outfile = os.path.splitext(infile)[0] + ".thumbnail" if infile != outfile: try: im = Image.open(infile) im.thumbnail(size, Image.Resampling.LANCZOS) im.save(outfile, "JPEG") except IOError: print "cannot create thumbnail for '%s'" % infile

  5. Make Script Executable Make the python script executable with the following command $ sudo chmod +x test.py

  6. Run Script Run python script with following command. Provide path to image file as first argument. $ python test.py /path/to/image

  7. Thank You Visit for details https://techimbo.com/how-to-resize-image-in-python/

More Related