LINUX, FOSS AND LIBRARY TECHNOLOGY ENTHUSIAST

Wednesday, January 25, 2023

Python script to convert, resize, and compress images in bulk

0 comments
Here is the modified version of the Python script created by Mr. A.J. Tomson, Librarian, Devagiri College, Kozhikode. It was helpful for creating an IDLINK.TXT and compressing images. But this modified script will help you convert images into jpeg irrespective of their format (jpg, png, or gif) and resize all images to 20kb and dimensions width 140px, height 158px without losing clarity of images and create a zip file.  

How to Use the Script

Organize your photos

Place all patron images in a folder. Ensure each photo name matches the patron’s card number.

Download the script

Open a terminal inside your image folder and run:

cd patron_images

wget -O idlink.py https://gist.githubusercontent.com/maheshpalamuttath/59a672a84d13ba12b9c01dedfdd9bd22/raw/045a468704ba9e77acee9e9fe74b561191a27a97/idlink.py

Install Python3 (if not installed)

sudo apt update

sudo apt install -y python3 python3-pip python3-venv zip unzip

python3 -m venv venv && source venv/bin/activate && pip install pillow

Make the script executable

chmod +x idlink.py

Run the script

./idlink.py

After the process finishes, you’ll find a zip file containing all compressed and resized JPEG images ready for use.

Go to Koha > Tools > Upload Patron Images.

Upload the zip file.


Reference:    

No comments:

Post a Comment