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 write a script for compressing the size of pictures in batch

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "how to write a script for compressing the size of pictures in batches". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to write a script for compressing the size of a batch of pictures.

A script used to compress pictures. Install # ImageMagick# first.

The code is as follows:

#! / bin/bash

# yum install ImageMagick

# cd / img/dir

For file in * / * .jpg; do

To_middle_file= "${file%.*} _ m.$ {file##*.}"; / / File name with suffix such as hello_m.jpg

To_small_file= "${file%.*} _ s.s. ${file##*.}"

Convert ${img}-resize 300x180! ${to_middle_file}

Ls ${to_middle_file}

Convert ${img}-resize 100x60! ${to_small_file}

Ls ${to_small_file}

Done

# convert resize argument

# 100x200 # width = 100,200 height

# 300x # width = 300, height = proportional

# x300 # width = proportional, height = 300

#! Indicates the cast size without adding "!" The picture will be compressed according to the proportion of the original picture.

At this point, I believe you have a deeper understanding of "how to write a script for bulk compression of pictures". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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

Development

Wechat

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

12
Report