convert in Linux
Introduction
With convert you can perform various manipulations with images in Linux
Installation
convert
Command 'convert' not found, but can be installed with: sudo apt install graphicsmagick-imagemagick-compat # version 1.4+really1.3.38-1, or sudo apt install imagemagick-6.q16 # version 8:6.9.11.60+dfsg-1.3build2 sudo apt install imagemagick-6.q16hdri # version 8:6.9.11.60+dfsg-1.3build2
You need to install imagemagick
sudo apt -y install imagemagick
Example
Let's convert an image with graffiti from the city of Torremolinos
Reduce the width to 800 pixels
convert graffiti.jpg -resize 800 graffiti800.jpg
Reduce the width to 500 pixels
convert graffiti.jpg -resize 500 graffiti500.jpg
Scripts
A script that compresses all jpg and png images to a given width
#!/bin/bash WIDTH=1600 for file in ./*; do EXT="${file##*.}" FULLNAME="${file##/}" if [[ $EXT = "jpg" ]] || [[ $EXT = "png" ]]; then convert $FULLNAME -resize $WIDTH $FULLNAME fi done
#!/bin/bash WIDTH=1000 resize_image() { file=$1 EXT="${file##*.}" FULLNAME="${file##/}" echo $FULLNAME if [[ $EXT = "jpg" ]] || [[ $EXT = "png" ]]; then convert $FULLNAME -resize $WIDTH $FULLNAME fi } for file in ./*; do resize_image $file done
Article author: Andrei Olegovich