Skip to main content
Drupal 8

Main navigation

  • Home
    • Question And Answer
    • NEWS
    • Projects
  • Tutorials - Drupal
    • Android
    • Other
User account menu
  • Log in

Breadcrumb

  1. Home

Images processing using ImageMagick (convert)

By editor , 11 June, 2016
Question

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

Resize images and set quality for Jpg

for i in $( ls ./*.jpg); do convert -resize 900 -quality 70% $i outs/$i; done

 

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 : http://www.imagemagick.org/Usage/blur/)

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
do
     darktable-cli "$pic" "$(basename ${pic%.CR2}.jpg)";
done

 

Tags

  • Shell
  • Linux
  • Images
Convert M4A, OGG or OPUS audio file in to MP3 on linux

Comments

Plain text

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

Links

  • Drupal.org
  • Drupal core release cycle
  • Drupal events with ease
  • Unit test with Drupal using PHPUnit (Drupal 10)
  • Tokens for file upload url
  • Tips for Docker
  • CKEditor inline image files usage for custom forms.
  • Install Docker on Linux Mint
  • Install PHP 8.1
  • Drupal Security Best Practices
  • Order and sort items with tabledrag
  • Add a custom service YAML container
  • Apply a patch with composer