Converting PNG to JPG (optimized):
# This is an optimized resizing command to convert PNG to JPG with minimal loss of image quality
outputPath=./resized
size=1200 # width
mkdir $outputPath
originalFormat=png
newFormat=jpg
mogrify -path $outputPath -format $newFormat -resize $size -filter Triangle -define filter:support=2 -unsharp 0.25x0.25+8+0.065 -dither None -posterize 136 -quality 82 -define jpeg:fancy-upsampling=off -define png:compression-filter=5 -define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude-chunk=all -interlace none -colorspace sRGB -strip *.$originalFormat
Resizing JPG & PNG Files On First-level Child Folders
# Set image sizing variables
size=2475x1650
newFormat=jpg
# Look into current directory for any folders, then create a sub-folder named 'resized'. Afterward, trigger the command to resize any jpg or png images to be dumped into the 'resized' sub-folders of each directory
for d in */ ; do
[ -L "${d%/}" ] && continue; # skip sym-links
outputPath=$(echo "$d""resized");
mkdir $outputPath;
mogrify -path $outputPath -format $newFormat -resize "$size"">" -filter Triangle -define filter:support=2 -unsharp 0.25x0.25+8+0.065 -dither None -posterize 136 -quality 82 -define jpeg:fancy-upsampling=off -define -interlace none -colorspace sRGB -strip $d*.{jpg,JPG,png,PNG};
done
Resizing JPG Files (Optimized):
# This is an optimized resizing command to convert PNG to JPG with minimal loss of image quality
outputPath=./resized
size=2400x1600 # height x width
mkdir $outputPath
originalFormat=jpg
newFormat=jpg
mogrify -path $outputPath -format $newFormat -resize $size -filter Triangle -define filter:support=2 -unsharp 0.25x0.25+8+0.065 -dither None -posterize 136 -quality 82 -define jpeg:fancy-upsampling=off -define -interlace none -colorspace sRGB -strip *.$originalFormat
Resizing JPG Files:
# This command would pickup all PNG images of current directory and create resized versions of them in the ./resized folder
mkdir ./resized
mogrify -path ./resized -resize 1200 *.jpg
Resize All and Only Images In a Directory, Including Sub-Directories
path=./
size=2400x1600
find $path -type f -exec file \{\} \; | awk -F: '{if ($2 ~/image/) print $1}' \
| while IFS= read -r imageFile; do \
mogrify -resize $size\> "$imageFile"; \
done
This would happen if the resized directory doesn’t exist
kim@kim-linux:~$ cd ~
kim@kim-linux:/Scans$ mogrify -path ./resized -resize 1200 *.png
mogrify-im6.q16: unable to open image `./resized//Military-Payment-Certificate-One-Dollar-Series-661-Backside.png': No such file or directory @ error/blob.c/OpenBlob/2874.
mogrify-im6.q16: WriteBlob Failed `./resized//Military-Payment-Certificate-One-Dollar-Series-661-Backside.png' @ error/png.c/MagickPNGErrorHandler/1641.
Categories: