Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to compress the size of pictures in batch under Linux system

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to compress the size of pictures in batches under the Linux system". In the operation of actual cases, many people will encounter this dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Installation and use of the Centos system:

Yum install ImageMagick

Then enter y to confirm that the installation can be completed.

Next, call the system command

The code is as follows:

# include

Int main ()

{

Printf ("Please install ImageMagick before run this programme, else it will not run correctlyn")

System ("mkdir small")

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 be modified imagemagick, which can convert the image format, compress the size, add watermarks and other operations, without the need to write a third-party program, you only need to write a simple SHELL script to complete the image compression operation, which is described below on UBUNTU:

Installation commands:

Sudo apt-get install imagemagick

Other linux have corresponding software installation commands. Here are two scripts I wrote to format and compress the images in batches:

Image format conversion. The example here is to convert a file in the format of [bB] [mM] [pP] (all BMP files) into a jpg file with a small footprint:

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`

# 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

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

This is the end of the content of "how to compress the size of pictures in batch under the Linux system". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report