Now the mobile phone users are very large, for mobile phone users have to consider the traffic, but the mobile network bandwidth is small, how the image compression on the internet is a problem, in Windows easy, there are many software, but there is no way on Linux?
After many searches, or found some way, here to share:
A powerful free picture tool that can be used under command line ImageMagick
Installation and usage of CentOS system:
Yum Install ImageMagick
Then enter Y to confirm the installation complete
Next Call system command
The code is as follows:
#include
int main ()
{
printf ("Please install ImageMagick the before run this programme, else it'll not run Correctlyn");
System ("mkdir small");
System ("CP *.jpg./small");
System ("Find./small-name ' *.jpg '-exec convert-resize 300x300 {} {};");
System ("PWD");
System ("rename. jpg _small.jpg small/*.jpg");
printf ("Nconvert pictures finished,plesae check ITN");
return 0;
}
The resize parameter of convert above can modify the ImageMagick, it can transform the format of the picture, compress the size, increase the watermark and so on, and do not need to write a third party's program, just write a simple shell script can complete the picture compression operation, Next on the Ubuntu introduction:
Install Command:
sudo apt-get install ImageMagick
Other Linux has the corresponding software installation commands, I wrote the following two scripts, the pictures are batch format and compression operations:
Image format conversion, here is an example of [BB][MM][PP] (all BMP files) in the format of the file, converted to a small space-occupying JPG file:
The code is as follows:
#!/bin/sh
For IMG on ' find./-name ' *. [BB] [MM] [PP] "'; Todo
#change Upper filename to lower
_imglower= ' echo $img |tr "[: Upper:]" "[: Lower:]" ';
#get file ' s basename
_basename= ' basename $_imglower. bmp ';
#get file ' s dir
_dirname= ' dirname $img ';
#get desc filename with path
_basefullname=$_dirname "/" $_basename ". jpg";
#do Convert
Convert $img $_basefullname;
#remove BMP File
RM $img;
echo "Deal $_basefullname successfully";
Done
Picture compression script:
The code is as follows:
For IMG on ' find./-name ' *. [JJ] [PP] [GG] "'; Todo
Convert-resize 85%*85% $img $img-resized;
RM $img;
MV $img-resized $img
Echo $img
Done
For IMG on ' find./-name ' *. [PP] [NN] [GG] "'; Todo
Convert-resize 85%*85% $img $img-resized;
RM $img;
MV $img-resized $img
Echo $img
Done
For IMG on ' find./-name ' *. [GG] [II] [FF] "'; Todo
Convert-resize 85%*85% $img $img-resized;
RM $img;
MV $img-resized $img
Echo $img
Done