Previously, when converting batches of image formats, we almost always did it in a graphical interface, by selecting various parameters. In fact, the graphical interface is just a shell, and if we talk about the efficiency of the conversion, the way of using commands would be better. So, is it more complicated to use commands to convert images? Not necessarily. With the help of a simple conversion program file NConvert, and its perfect format help information, a simple line of command can complete the complex task of converting batches of pictures, compared to the operation of layers of menus or windows, in fact, more simple.
Tip: NConvert is a powerful command line multi-platform batch image processor with over 80 command forms and compatibility with 500 image formats. NConvert is a freeware that is neither advertised nor maliciously bundled, and is available for free for private or educational use (including non-profit organizations). Users can help developers by making small donations. However, for commercial use, a license must be purchased.
The NConvert program is run from the command line by opening a command prompt window and organizing the command line as “NConvert parameter sequence filename”. If the images are stored directly in the same folder as NConvert, the command line will eliminate the need for long paths. Here are some practical examples to illustrate each of them.
If you want to convert images in batches, for example, to convert all png images in this directory with the file prefix to tiff format, you can use the following command (Figure 1).
nconvert -out tiff file?.png
NConvert can also perform batch conversion of image resolutions. To convert all images with the extension png to 640*480 pixels, you can use the command with the -resize parameter (Figure 2).
nconvert -out png -resize 640 480 *.png
It is possible to maintain the aspect ratio while scaling the images. For example, the following command with the aspect ratio parameter -ratio keeps the aspect ratio constant while scaling all jpg images to 480 in width, so that the image height is automatically determined proportionally, converting the image to jpeg format.
(Figure 3) Batch Scaling with Aspect Ratio
nconvert -out jpeg -ratio -resize 480 0 *.jpg
For color control during image conversion, add a color parameter. For example, the following command uses the -truecolors parameter to indicate that the color is set to true color while converting the gif image to jpeg (Figure 4).
nconvert -out jpeg -truecolors *.gif
The following command adds the -dither parameter, which will use 256 colors and Bayer dithering in the conversion.
nconvert -out gif -dither -colors 256 *.jpeg
File format conversion and scaling can also be done simultaneously. For example, the following commands all change the resolution or image size ratio while converting a jpeg image to png format (Figure 5).
nconvert -out png -resize 510 230 *.jpeg
nconvert -out png -ratio -resize 510 0 *.jpeg
nconvert -out png -ratio -resize 0 510 *.jpeg
nconvert -out png -resize 200% 200% *.jpeg
The format conversion process also supports renaming the file serial number. For example, the following command is converting all file-headed pic images to jpeg while naming them with a numeric ending sequence like file name res01 to res10 (Figure 6).
nconvert -out jpeg -n 1 10 1 -o res#.jpg file##.pic
Fuzzy file name substitution is also supported during format conversion. For example, the following command converts file.tga to jpg format while the output file name directly references the original file name (Figure 7).
You can use % to specify source filename in dest filename.
If you want to introduce the above command into a batch file, write the % sign repeatedly in the form of %%. Write the following command in the batch file to convert all image files in tga format to a file with result_ prefix plus the original file name in jpeg format (Figure 8).
nconvert -out jpeg -o result_%%.jpg *.tga
Tip: If you don’t understand the meaning of the individual parameters used in the nconvert command above, you can run the following command in a command prompt window for help.
If you wish to collect the help information into a single text, run the following command to do so.
nconvert -help > nchelp.txt
Where nchelp.txt is the generated help text file, this file name can be specified by the user and can be opened with Notepad to view it.