Loading...
X

How to install and use ImageMagick on Windows

Contents

1. What is ImageMagick. What is ImageMagick for

2. Where to download ImageMagick for Windows. How to install ImageMagick on Windows

3. How to run ImageMagick in Windows

4. How to run ImageMagick commands in Windows

5. How to convert images with ImageMagick in Windows

6. How to reduce the size of photos in ImageMagick

6.1 How to increase the level of image compression

6.2 How to reduce the resolution of photos to save space

7. How to modify images in ImageMagick. Options of magick

7.1 How to imitate an oil painting

7.2 How to imitate a charcoal drawing

7.3 How to mimic a pencil sketch

7.4 How to make an image black and white

7.5 How to create an image negative

7.6 How to flip and flop images (vertical and horizontal image mirroring) on the Linux command line

7.7 How to rotate an image on the Linux command line

7.8 Rolling images. Film effect

7.9 How to simulate a Polaroid photo on the command line

7.10 How to reduce image noise on the Linux command line

7.11 How to increase image noise on the Linux command line

7.12 How to lighten or darken the edges of an image

7.13 How to create a border around an image

7.14 How to create a vignette

7.15 How to lighten an image. How to increase exposure

7.16 How to make an image darker. How to reduce exposure

8. Batch image processing in ImageMagick

Task 1: convert all JPG files in the current directory to WebP format and save them in a new folder.

Task 2: convert all JPG files in the current directory to AVIF format and save them in a new folder.

Task 3: Reduce the size of all JPG files in the current folder. Use an increase in the compression level as a method for reducing the size.

9. Let’s continue to get acquainted with ImageMagick


1. What is ImageMagick. What is ImageMagick for

ImageMagick is a powerful tool for working with images. This program can do a variety of things with photos in any format. For example, ImageMagick can convert images from one format to another, and dozens of formats are supported (at least in Linux, in Windows support for some formats may be limited (read only) or not work due to the lack of necessary libraries).

In addition to converting, ImageMagick can add inscriptions in various styles to an image, rotate, crop an image, apply various effects to the entire image or to its individual areas, reduce the size of an image file by reducing the size (number of pixels) and the degree of compression, display detailed information about images, perform the listed and other actions in batch mode, that is, for a large number of files at once.

At the same time, ImageMagick is free and this program has an open source code.

So why have you never seen or used ImageMagick if it is such an amazing tool? Well, ImageMagick is a command line utility. Yes, to use ImageMagick you need to learn the command structure of this package and get a little familiar with the command line. But it is worth it! Your efforts will be rewarded a hundredfold, I guarantee you!

2. Where to download ImageMagick for Windows. How to install ImageMagick on Windows

ImageMagick runs on Windows 10 (x86, x64 and arm64) or newer, or Windows Server 2012 or newer.

Memory can be an important factor, especially if you are going to be working with large images. A minimum of 512 MB of RAM is recommended, but the more RAM the better. Although ImageMagick works well on a single-core computer, it automatically runs in parallel on multi-core systems, which significantly reduces execution time.

Go to the official page of the program: https://imagemagick.org/script/download.php#windows

You may be confused by the abundance of file options for download. If you do not want to deal with it, then the top option will suit most users and offer the most options.

The versions with Q8 in the name support 8-bit images (i.e. 8-bit red, 8-bit green, etc.), while Q16 in the file name supports color depth up to 16 bits. The Q16 version allows you to read or write 16-bit images without losing precision, but requires twice as many resources as the Q8 version. The versions with dll in the file name include the ImageMagick libraries as dynamically linked libraries. If you do not have a 32-bit Windows OS, we recommend this version of ImageMagick for 64-bit Windows:

Download the setup file and run it as an installer for any other program. You will see a standard question (for example, the path to install the program) – you can leave everything as default.

A very important setting is shown in the next window, namely “Add application directory to your system path” (to the System PATH environment variable). Thanks to this setting, working with ImageMagick commands will be much easier – we will be able to run the program by its short name, without having to specify the full path to the executable file. By default, this setting is already enabled – just leave everything as is.

3. How to run ImageMagick in Windows

After the installation is complete, you can start using the program.

To do this, open the Windows command line – this can be the Terminal application, CMD, PowerShell console – whatever.

For example, to open the Terminal window, press Win+x and select “Terminal” in the context menu that opens.

Or find the Terminal application using the search in the “Start” menu.

OR to open CMD, press Win+r and run

cmd

So, now that the command prompt is open, type your first ImageMagick command

magick -list format

And press Enter.

This will output a table with a lot of data – this is information about the image formats that ImageMagick supports.

See also: ImageMagick error on Windows: “magick: unable to open image ''test': No such file or directory @ error/blob.c/OpenBlob/3565. magick: no decode delegate for this image format `' @ error/constitute.c/ReadImage/741.” (SOLVED)

4. How to run ImageMagick commands in Windows

Typical ImageMagick commands look like this:

magick INPUT_FILE_NAME OUTPUT_FILE_NAME

magick INPUT_FILE_NAME OPTIONS OUTPUT_FILE_NAME

In these commands:

  • magick – the name of the executable file that performs the action
  • INPUT_FILE_NAME – the path to the file you want to process
  • OPTIONS – options may be missing, several examples of using options will be discussed below
  • OUTPUT_FILE_NAME – the path to the new file where the command result will be saved

Please note that the path to the files can be specified as a relative path or as an absolute path. If only the file name is specified (without folders and subfolders), the program will look for a file with this name in the current working directory.

See also:

In order not to specify the full path to the files, you can go to the folder with photos in the command line. For example, the photos I want to process are in the folder C:\Users\MiAl\Downloads\pic\, then I need to run the following command to go there:

cd C:\Users\MiAl\Downloads\pic\

5. How to convert images with ImageMagick in Windows

The command for converting files is quite simple – you need to specify the file you want to convert, and then the file with the extension you want to convert the photo to.

For example, I want to convert the file 20240111_130337.jpg to WebP format, then I need to specify the name of the file with the new format:

magick 20240111_130337.jpg 20240111_130337.webp

As a result of the command, a new file 20240111_130337.webp was created:

As a result of converting to WebP format, the photo takes up less space while maintaining the quality of the original. As you can see, the WebP format is well supported by both Windows OS and web browsers:

You can choose any file name for the new file – the main thing is to correctly specify the desired file extension, for example:

magick 20240111_130337.jpg island.webp

ImageMagick supports a variety of image formats, for example, I can convert a photo to the modern AVIF format:

magick 20240116_121213.jpg 20240116_121213.avif

As a result of the command, a new file 20240116_121213.avif was created:

A file in AVIF format takes up several times less space than JPG, while maintaining the quality of the original:

See also: Convert images from and to any format

6. How to reduce the size of photos in ImageMagick

Let's look at another useful example of using ImageMagick, namely changing the compression of photos.

First, a little theory.

Photos can be compressed in several ways, for example:

1) Convert to a format that supports a better compression ratio (for example, AVIF, HEIC)

2) Increase the compression ratio – this will affect the quality of the photo, but will also reduce the amount of space occupied

3) Reduce the number of pixels – this will also reduce the amount of space taken up, as for the quality of the photo, it will be affected, for example, by what device you are viewing it on and whether you zoom in when viewing the photo

6.1 How to increase the level of image compression

Let's start with increasing the compression ratio. To do this, use a command like this:

magick ИМЯ_ВХОДНОГО_ФАЙЛА -quality ЗНАЧЕНИЕ ИМЯ_ВЫХОДНОГО_ФАЙЛА

As VALUE, you need to specify a number from 1 to 100 – the lower the number, the higher the compression level, i.e. the file will take up less space, but the photo will look worse.

For example, I want to compress the file 20240116_115638.jpg (size 3.7 megabytes) and save the compressed image to a new file called beach.jpg:

magick 20240116_115638.jpg -quality 40 beach.jpg

This results in a file called beach.jpg with a size of 775 kilobytes:

Clicking on the file will open its full size after compression:

6.2 How to reduce the resolution of photos to save space

Another way to reduce the size of the file is to reduce the number of pixels in it, for this you can use a command like this:

magick INPUT_FILE_NAME -resize PERCENTAGE% OUTPUT_FILE_NAME

As a PERCENTAGE, you can specify a number – for the image to be reduced in size, this number must be less than 100, for example:

magick 20240116_115638.jpg -resize 50% small.jpg

As a result, a new file named small.jpg is created, which looks quite acceptable on the monitor and takes up only 679 kilobytes:

With the -resize option, you can specify the desired width of the new file (the height will be selected automatically to maintain the image proportions). For example, with the following command I set the file width to 1000 pixels:

magick 20240116_115638.jpg -resize 1000 w1000.jpg

The result is a file with a width of 1000 pixels:

If you want to set a specific height (so that the width is selected automatically), then this is also possible – the following command will compress the file to a height of 1000 pixels:

magick 20240116_115638.jpg -resize x1000 h1000.jpg

The result is a file with a height of 1000 pixels and an automatically selected width to maintain the previous proportions:

I think you get the idea and learned how to compress files in the desired way in the command line.

7. How to modify images in ImageMagick. Options of magick

How to imitate an oil painting

To make the photo look like a painting, use the -paint RADIUS option.

This option creates an imitation of an oil painting.

Each pixel is replaced by the most frequently occurring color in a circular neighborhood whose width is determined by the radius.

Command example:

magick IMAGE.jpg -paint 4 test1.jpg

Result:

How to imitate a charcoal drawing

To make the photo look like it was drawn with charcoal, use the -charcoal RADIUS option.

Command example:

magick IMAGE.jpg -charcoal 5 test2.jpg

Result:

How to mimic a pencil sketch

The -sketch GEOMETRY option creates a simulated pencil sketch.

Command example:

magick IMAGE.jpg -sketch 5 test3.jpg

Result:

This option has the following syntax options:

  • -sketch radius
  • -sketch radius{xsigma}+angle

The last version of the option creates a sketch with the specified radius, standard deviation (sigma) and angle. The specified angle is the angle at which the image is drawn. This is the direction people think the object is coming from.

How to make an image black and white

How to convert an image to black and white on the Linux command line? With the -monochrome option, you can convert an image to black and white.

Command example:

magick IMAGE.jpg -monochrome test4.jpg

Result:

How to create an image negative

With the -negate option, you can replace each pixel with its complementary color.

The red, green, and blue intensity of the image is inverted. White becomes black, yellow becomes blue, and so on. Use +negate to invert only the pixels in a grayscale image.

Command example:

magick IMAGE.jpg -negate test5.jpg

Result:

How to flip and flop images (vertical and horizontal image mirroring) on the Linux command line

To flip and flop an image horizontally or vertically, use the options:

  • -flip (image will be flipped upside down)
  • -flop (the image will be flopped, mirrored from left to right - just like in a mirror)

Command example:

magick IMAGE.jpg -flip test6.jpg

Result:

Command example:

magick IMAGE.jpg -flop test7.jpg

Result:

How to rotate an image on the Linux command line

To rotate an image, use the -rotate DEGREES option. Degrees can be set to either positive (for clockwise rotation) or negative (for counterclockwise rotation) values. For example:

magick IMAGE.jpg -rotate 30 test8.jpg
magick IMAGE.jpg -rotate -30 test8.jpg

By default, the empty corners that appear will be filled with white, if you want to change the color, then use the -background option:

magick IMAGE.jpg -background VioletRed -rotate 30 test8.jpg

You can see the names of all colors with the following command:

magick -list color

See also:

If you want to rotate the image and fill the empty corners with stretched bands of color around the edges of the image, then use the -distort ScaleRotateTranslate ANGLE option, for example:

magick IMAGE.jpg -distort ScaleRotateTranslate 30 test9.jpg

If you want to have the image scaled up to fill the entire space instead of filling empty edges, then use the -distort ScaleRotateTranslate SCALE,ANGLE option, for example:

magick IMAGE.jpg -distort ScaleRotateTranslate 1.5,30 test10.jpg

The -distort ScaleRotateTranslate option can take a different number of arguments, which also change its behavior:

magick IMAGE.jpg -distort ScaleRotateTranslate 500,500,30 test10.jpg

See the -distort option help for details: https://imagemagick.org/script/command-line-options.php#distort

Two more options related to rotating and flipping images:

  • -transpose: will flip the image diagonally from top left to bottom right. This option mathematically transposes an array of pixels. It is equivalent to the “-flip -rotate 90” option sequence.
  • -transverse: Flips the image diagonally from the bottom left image to the top right. Equivalent to “-flop -rotate 90”.

Examples of using:

magick IMAGE.jpg -transpose test11.jpg
magick IMAGE.jpg -transverse test11.jpg

Rolling images. Film effect

The -roll GEOMETRY option rotates the image vertically or horizontally so that its parts are on the opposite side. As an argument to the -roll option, you need to specify two numbers, which can be both positive and negative, which indicate the number of pixels by which you want to rotate the image vertically and horizontally.

Command example:

magick IMAGE.jpg -roll +130+150 test11.jpg

Result:

How to simulate a Polaroid photo on the command line

With the -polaroid ANGLE option, you can simulate a Polaroid photo.

Angle indicates how much the image should be rotated.

Command example:

magick IMAGE.jpg -polaroid -10 test12.jpg

Result:

How to reduce image noise on the Linux command line

The -noise GEOMETRY option does not work in recent versions of ImageMagick because it has been deprecated. Use -statistic NonPeak INTENSITY instead.

For example:

magick IMAGE.jpg -statistic NonPeak 3 test13.jpg

Too high INTENSITY values make the image unrealistic.

How to increase image noise on the Linux command line

To increase noise, use the following set of options: -attenuate INTENSITY +noise TYPE

For INTENSITY, enter a number (default 1.0). For Noise TYPE, select from the following options:

  • Gaussian
  • Impulse
  • Laplacian
  • Multiplicative
  • Poisson
  • Random
  • Uniform

Note that Random will replace the image with noise, not add noise to the image. Use Uniform if you want to add random noise to an image.

Command example:

magick IMAGE.jpg -attenuate 1.5 +noise Gaussian test14.jpg

Result:

You can achieve the same result with the -evaluate option, for example:

magick IMAGE.jpg -evaluate Gaussian-noise 1.5 test14.jpg

Detailed description of the -evaluate option and its possible arguments: https://imagemagick.org/script/command-line-options.php#evaluate

How to lighten or darken the edges of an image

The -raise VALUE option will lighten or darken the edges of the image to create a 3D effect.

This will create a 3D effect. Use -raise to create a raised effect, otherwise use +raise.

magick IMAGE.jpg -raise 50 test22.jpg
magick IMAGE.jpg +raise 50 test22.jpg

Unlike the similar -frame option (discussed below), -raise does not resize the image.

How to create a border around an image

To frame an image, use the -frame option.

If you want a single-color frame without effects, then specify a single number after -frame:

magick IMAGE.jpg -mattecolor peru -frame 19 test23.jpg

If you want a frame with a 3D effect, then specify four numbers: -frame AxA+B+C:

magick IMAGE.jpg -mattecolor peru -frame 19x19+3+6 test23.jpg

The first two numbers (A) determine the thickness of the frame, the second number (B) determines the thickness of the outer edge, the last number (C) determines the thickness of the inner edge.

The -mattecolor option sets the border color.

You can see the names of all colors with the following command:

magick -list color

See also:

How to create a vignette

The -vignette option softens the edges of the image in a vignette style.

Format: -vignette RADIUS{xSIGMA}{+-}x{+-}y{%}

The falloff of the vignette effect is controlled by RADIUSxSIGMA (there are two variables, radius and sigma, and the multiplication sign, i.e. radius x sigma). For nominal rolloff, this would be set to 0xsigma. A value of 0x0 will produce a circle/ellipse with no rolloff. The arguments x and y control the size of the circle. Larger values decrease the radii and smaller values increase the radii. Values of +0+0 will generate a circle/ellipse the same size as the image. The default values for x and y are 10% of the corresponding image dimension. Thus, the radii will be decreased by 10%, i.e., the diameters of the circle/ellipse will be 80% of the corresponding image dimension. Note, the percent symbol in a geometry affects x and y, whereas radius and sigma are absolute (e.g., -vignette "0x2+10%+10%").

Command examples:

magick IMAGE.jpg -vignette 20x100 test24.jpg
magick IMAGE.jpg -vignette 0x100 test24.jpg

Result of the last command:

Many examples of how to make various frames and frames for images can be found at the link: https://imagemagick.org/Usage/thumbnails/

How to lighten an image. How to increase exposure

To increase the amount of white, use the -sigmoidal-contrast NUMBER,0% option. The larger the NUMBER, the stronger the change will be, for example:

magick IMAGE.jpg -sigmoidal-contrast 4,0% test25.jpg

To reduce the amount of black, use the +sigmoidal-contrast NUMBER,100% option. The larger the NUMBER, the stronger the change will be, for example:

magick IMAGE.jpg +sigmoidal-contrast 4,100% test25.jpg

How to make an image darker. How to reduce exposure

To reduce the amount of white, use the +sigmoidal-contrast NUMBER,0% option. The larger the NUMBER, the stronger the change will be, for example:

magick IMAGE.jpg +sigmoidal-contrast 4,0% test26.jpg

To increase the amount of black, use the -sigmoidal-contrast NUMBER,100% option. The larger the NUMBER, the stronger the change will be, for example:

magick IMAGE.jpg -sigmoidal-contrast 4,100% test26.jpg

8. Batch image processing in ImageMagick

You may quite reasonably point out that the above operations do not require a command line – many users can do similar actions in the graphical interface. In general, this is true (especially compression and rotation of files), but when it comes to conversion, ImageMagick supports many more formats. And the main advantage of the command line is automation.

Yes, you can quickly compress one or several files in the graphical interface – it will take some time, perhaps comparable to similar actions in the command line. But imagine that you need to process hundreds or even thousands of files – it will take you many hours, and in the command line it will be done automatically and much faster.

So, let's consider several scenarios.

Task 1: convert all JPG files in the current directory to WebP format and save them in a new folder.

Let's create a folder where the files will be written after conversion:

mkdir webp

The following command will read all .jpg files in the current directory one by one, convert them to WebP format and save them to the “webp” directory with their previous names:

magick *.jpg +adjoin -set filename:currentfile '%t' 'webp/%[filename:currentfile].webp'

After the command has completed, check the contents of the “webp” folder.

There can be any number of files – the program will perform all actions automatically, and the speed of the task will depend only on the power of your computer.

Task 2: convert all JPG files in the current directory to AVIF format and save them in a new folder.

Let's create a folder where the files will be written after conversion:

mkdir avif

Run the command to convert:

magick *.jpg +adjoin -set filename:currentfile '%t' 'avif/%[filename:currentfile].avif'

After the command has completed, check the contents of the “avif” folder.

Task 3: Reduce the size of all JPG files in the current folder. Use an increase in the compression level as a method for reducing the size.

Let's create a folder where the files will be written after compression:

mkdir compressed

Run the command to compress the files:

magick *.jpg -quality 40 -set filename:currentfile '%t' 'compressed/%[filename:currentfile].jpg'

After the command has completed, you will find the compressed files in the “compressed” folder.

Please note that the files now take up less disk space:

9. Let’s continue to get acquainted with ImageMagick

If you have felt the full power of the command line and ImageMagick, then you can continue to get acquainted with this program on the next page: ImageMagick guide: installing, using, and troubleshooting

The examples from this guide are applicable to ImageMagick in Linux and Windows.


Leave Your Observation

Your email address will not be published. Required fields are marked *