CentOS batch compression image size operation example

  

CentOS system operation, ImageMagick is a picture processing tool, can be used to compress the size of the picture, then how to use ImageMagick to process pictures under CentOS? The following small series will introduce you to CentOS using ImageMagick to compress the size of the image in batches. Let's learn together. Installation of free images to use powerful tool ImageMagick

Centos system in line that can be used

a more useful commands:

yum install ImageMagick

Enter y to confirm the installation is complete

Next call the system command

The code is as follows:

#include "stdio.h"

Int main()

{

printf(“Please install ImageMagick before run this programme , else it will not run correctlyn”);

system(“mkdir small&rdquo ;);

system(“cp *.jpg ./small”);

system(“find./small -name ‘*.jpg’ -exec convert -resize 300×300 {} {} \\;”);

system(“pwd”);

system(“rename .jpg _small.jpg small/*.jpg”) ;

printf(“nConvert pictures finished,plesae check itn”);

return 0;

}

The resize parameter in the above convert can modify imagemagick, which can perform image conversion, size compression, and watermark on the image without having to write a third-party program. Just write a simple SHELL script. Complete the image compression operation, then introduce it on UBUNTU:

Installation command:

sudo apt-get install imagemagick

Other linux has corresponding software installation commands, the following I wrote two scripts for batch formatting and compression of images:

Image format conversion, the example here is a file in [bB][mM][pP] (all BMP files) format. Convert to a small jpg file:

The code is as follows:

#! /bin/sh

for img in `find. /-name “*.[bB][mM][pP]“`; do

#change upper filename to lower

_imglower=`echo $img| Tr “[:upper:]” “[:lower:]“`;

#get file’s basename

_basename=`basename $_imglower .bmp`;< Br>

#get file’s dir

_dirname=`dirname $img`;

#get desc filename with path

_basefullname=$_dirname”/&rdquo ;$_basename”.jpg”;

#do convert

convert $img $_basefullname;

#remove bmp file

rm $img;< Br>

echo “deal $_basefullname successfully”;

done

Image compression script:

The code is as follows:

for img in ` Find. /-name “*.[jJ][pP][gG]“`; do

convert -resize 85%*85% $img $img-resized;

rm $ Img;

mv $img-resized $img

echo $img

done

for img in `find . /-name “*.[pP][nN][gG]“`; do

convert -resize 85%*85% $img $img-resized;

rm $ Img;

mv $img-resized $img

echo $img

done

for img in `find . /-name “*.[gG][iI][fF]“`; do

convert -resize 85%*85% $img $img-resized;

rm $ Img;

mv $img-resized $img

echo $img

done

The above is how to use ImageMagick to compress image size in batches under CentOS Introduced, after installing the ImageMagick tool, you can use the image compression script to compress the image size.

Copyright © Windows knowledge All Rights Reserved