Method of bulk compressing picture size under Linux system

Source: Internet
Author: User
Tags imagemagick printf

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.