Images processing using ImageMagick (convert) | Drupal 8

Images processing using ImageMagick (convert)

Submitted by editor on Sat, 06/11/2016 - 23:54

How to convert image using 'convert' ?

Crop images using convert (ImageMagick)

Example (Single file):
convert input.jpg -crop 1300x950+312+72 crop.jpg
convert input.jpg -crop 1300x950-100-50 crop.jpg

Resize images using convert (ImageMagick)

convert -resize 1024x768 *.JPG new_.jpg
convert -resize 25% *.JPG new_.jpg


Batch process (bulk processing - shell/batch script)

#Example 1. Crop images
for i in $( ls Renamed/*.jpg); do convert -crop 1300x950+312+72 $i outs/$i; done
#Example 2 Resize images
for i in $( ls ./*.jpg); do convert -resize 1024 $i outs/$i; done
#Example 3. Rename (With aprefix)
for i in $( ls *.jpg); do convert $i FOLDER/PREFIX-$i; done

Another example of batch process : Unzip file
for z in *.zip; do unzip "$z"; done

Few use full Examples:

Blur an image (-blur XxX, Ex : 1x1, 1x2, 2x1 .... 0x8) (Help :

convert input.png -blur 0x8 output.png
convert input.png -channel RGBA -blur 0x8 ourput.png

Bulk Rename (image or any file):

# Chang name to 2 digits name, starting from 1.
num=1; for i in *.jpg; do mv "$i" "$(printf '%02d' $num).${i#*.}"; ((num++)); done
#Add an index number before.
num=1; for i in *.jpg; do mv "$i" "$(printf '%02d' $num)-$i"; ((num++)); done
#Add a Prefix
for i in *.jpg; do mv "$i" "New-Name-$i"; done
#Add a suffix
for i in *.jpg; do mv "$i" "$i-New-Name"; done


Example Convert CR2 raw image with darktable

for pic in *.CR2
     darktable-cli "$pic" "$(basename ${pic%.CR2}.jpg)";


Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.