ImageMagick is an open source graphical image editing software library that can interact with many programming languages via command line or API. It can be used to create, edit and composite bitmap images and supports more than 100 file formats. It supports many common image processing operations such as compression, cropping, resizing, rotation, blurring, and more.
To install ImageMagick on a mac, there are a few different ways:
1. Homebrew
Homebrew is a very popular package management tool on macOS. When using Homebrew, execute the following command to install ImageMagick:
brew install imagemagick
2. MacPorts
MacPorts is an alternative to Homebrew for macOS software management that also provides ImageMagick installation. You can install ImageMagick with the following command:
sudo port install ImageMagick
3. Download the official installation package
If you don't want to use terminal commands to install ImageMagick, the best way is to download the executable installation file from the official website: https://imagemagick.org/script/download.php . After downloading, double-click the .dmg file and follow the prompts to install it.
Commonly used ImageMagick command cases
crop picture
Using -crop
the parameter, you can crop the image. For example, the command to input.jpg
cut into 400x400
a picture with a size of and save it output.jpg
as is:
convert input.jpg -crop 400x400+0+0 output.jpg
change picture size
Use -resize
the parameter to change the image size. For example, 800x600
the command to resize an image of size is:
convert input.jpg -resize 800x600 output.jpg
picture rotation
Use -rotate
the parameter to rotate the image. For example, the command to rotate an image 45 degrees counterclockwise and save it as output.jpg
is:
convert input.jpg -rotate -45 output.jpg
Add image watermark
Use -composite
parameters and -gravity
parameters to add image watermark. For example:
convert input.jpg watermark.png -gravity southeast -composite output.jpg
text watermark
Use -annotate
the parameter to add a text watermark. For example, the command to add "Hello World" to the center of the picture is:
convert input.jpg -pointsize 72 -draw "text 50,100 'Hello World'" output.jpg
Compress Pictures
convert input.jpg -quality 80 output.jpg
This command will input.jpg
compress to 80% quality and save the output tooutput.jpg
resize picture
convert input.jpg -resize 50% output.jpg
This command will input.jpg
resize to 50% of its original size and save the output tooutput.jpg
rotate picture
convert input.jpg -rotate 90 output.jpg
This command will input.jpg
rotate 90 degrees counterclockwise and save the output tooutput.jpg
crop picture
convert input.jpg -crop 500x500+100+100 output.jpg
This command will input.jpg
crop a 500x500 image from the image, starting at (100,100), and save the output tooutput.jpg
image blur
convert input.jpg -blur 0x8 output.jpg
This command will apply a Gaussian filter, input.jpg
blur the image, and save the output tooutput.jpg
add watermark
convert input.jpg -font Arial -pointsize 50 -draw "gravity south fill black text 0,12 '© Your Company Name' fill white text 1,11 '© Your Company Name'" output.jpg
This command will add copyright text in Arial font size 50 to the bottom of the input image and display the text in white on a black background.
Crop all the pictures in the directory and save them in another directory:
mkdir output
mogrify -path output -trim *.jpg
mogrify
The command can modify multiple images in batches at one time. The above example will crop all JPG images in the current directory and store them in the output directory. After the cropping is completed, the processing results will be displayed. -trim
option specifying to remove borders around each image, possibly empty canvas area.
Summarize
ImageMagick is a heavyweight tool for image processing. Its main features are diversification, cross-platform, open source and free, etc. We can easily complete most image processing tasks through various commands, and can also be used with various programming languages (such as Python, PHP, etc.), which greatly increases its application scenarios and scalability, whether it is beginners or advanced Users are worth exploring and using.