Method of bulk compressing picture size under Linux system
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
#include <stdio.h>
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 in convert above can be modified
ImageMagick, it can format the image conversion, size compression, increase watermark and other operations, and do not need to write a third-party program, just write a simple shell script can complete the picture compression operation,
Next on the Ubuntu introduction {reprint}:
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:
[C-sharp] View plaincopy
#!/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:
[C-sharp] View plaincopy
for IMG on ' find./-name ' *. [JJ] [PP] [GG] "'; Do
convert-resize 85%*85% $img $img-resized
RM $img
MV $img-resized $img
Echo $img
doing
for img In ' Find./-name ' *. [PP] [NN] [GG] "'; Do
convert-resize 85%*85% $img $img-resized
RM $img
MV $img-resized $img
Echo $img
doing
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