#!/usr/bin/env bash
# GNU shell script to image mass cropping
# --------------------------------------------------------------------------
# Copyleft (Ɔ) Yoander Valdés(sedlav) Rodríguez <https://www.librebyte.net/>
# This script is released under GNU GPL 2 + licence
# --------------------------------------------------------------------------
# Use:
#
# This script find all images under current DIR, calculate new size and crop
# every image. This script asks if you want to keep original file or
# override it. Download the script give it exec perms and put it on
# /usr/local/bin.
# --------------------------------------------------------------------------
#
# Verify if ImageMagick suite is installed
#
( ! which identify convert &>/dev/null ) && { echo You must install ImageMagick suite; exit 1; }
#
# Ask for original file keeping
#
read -p "Do you want to keep original file [y|n]:" answer
#
# Pattern for jpg, jpeg, png, gif, tiff files
#
PATTERN='.*.(jpe?g|png|gif|tiff)$'
#
# Find and read every file that match above pattern in current DIR
#
find $(pwd) -regextype posix-egrep -iregex $PATTERN -type f -print0 | while read -d $'' file; do
# Get the image size new
size=$(identify "$file" | awk '{ print $3 }' | awk -Fx -v to_crop=20 '{ print $1"x"$2-to_crop}')
# New file name
cropped_name=$(dirname $file)/cropped_$(basename "$file")
# Crop the image
convert "$file" -crop $size+0+0 "$cropped_name"
# Rename to original name
[[ $answer =~ ^[0Nn]$ ]] && [[ -e "$cropped_name" ]] && mv -f "$cropped_name" "$file"
done
From : https://www.librebyte.net/en/multimedia ... s-in-mass/
Script to crop images en masse
If this is a matter of using someone elses images without their prior permission it is morally unethical!" Cropping images in mass
ImageMagick
Recently a friend told me:
I have to remove the watermark of hundreds of images, you could do it with a program like GIMP but are hundreds of images, I know that you can automate this process using some commands of the ImageMagick suite; I need your help to make the script in bash."
Hello all.
You don't need to call in the entire army (Image Magick)
when a commando (netpbm) can do the job.
Depending on your Pup, you may have part of the netpbm kit already installed,
To check, open a console and typeThe full netpbm package has a couple of crop utilities.
Overview of netpbm
List of netpbm graphic utilities
Search for "crop" (without the quotation marks)
Getting netpbm
You may want to check if the PPM for your Pup offers netpbm.
If not, netpbm at SourceForge has a 64bit deb package and the source available.
No 32-bit pkg though; if there is a need, I'll compile a 32-bit package from source.
IHTH
You don't need to call in the entire army (Image Magick)
when a commando (netpbm) can do the job.
Depending on your Pup, you may have part of the netpbm kit already installed,
To check, open a console and type
Code: Select all
cd /usr/bin
ls p?m*
Overview of netpbm
List of netpbm graphic utilities
Search for "crop" (without the quotation marks)
Getting netpbm
You may want to check if the PPM for your Pup offers netpbm.
If not, netpbm at SourceForge has a 64bit deb package and the source available.
No 32-bit pkg though; if there is a need, I'll compile a 32-bit package from source.
IHTH
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
It crops. It cuts 20 px from the bottoms of all images, regardless of their size. One crop fits allFlash wrote:Is it actually cropping, or is it shrinking the image by reducing the number of pixels, without cutting off large bits?

IMO this script is too limited and too complicated.
Using convert one can achieve the same result with a one-liner in ROX:
1) in ROX-Filer select the images you want to crop
2) Open a shell command entry box (Shortcut Schift+!)
3) Copy following command into the box and hit Enter
Code: Select all
for i in "$@" ;do convert "$i" -crop -0-20 "cropped_$i"; done