Get the App
SLTechnology News&Howtos  ›  Development  › 

How to write a script for compressing the size of pictures in batch

Shulou Source: shulou.com Published: 2022-06-03 08:06:10 09月19日 Update

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!

Tags: Picture size script content learning practical deeper code interest suffix practicality practical easy to operate file file name method more friends ratio website Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker macOS Huawei NVidia OPPO Reno