Batch compression of image scripts on Ubuntu

Source: Internet
Author: User
Article Title: script for batch Image Compression on Ubuntu. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Many photos taken with DC are very large in size. Sometimes we need to reduce the size. Recently, google found some useful commands and wrote a small script, the tool used for reference is powerful imagemagick.

If you have not installed it, you can install it through xinti,

# Sudo apt-get install imagemagick

The required command is convert.

The script I wrote uses two parameters: resize and font.

Resize is used to narrow down the image,

Usage is

-Resize image size

For example

-Resize 50% x50 %

This parameter reduces the length and width of the source image by 50%.

I used to reduce the image size to compress the image size. Of course, you can also compress the image by changing the image quality.

As the name implies, the parameter for changing the image quality is-quality.

-Quality 70

This parameter indicates that the image quality needs to be compressed to 70% (basically the difference between the image quality and the source image)

Add font watermark

The parameter is

-Font name-fill font color-pointsize font size-draw "text font start coordinate" text content ""

For more information, see man,

Finally, let's look at the simple script I wrote.

# Imagezoom. sh

For img in 'ls *. JPG '; do convert-resize 50% x50 % convert-fonthelvetica-fill white-pointsize 36-draw 'text "Pictures ByPDAsk.net"' $ img Resized-$ img; done

The function of this script is to scale down all JPG files under the directory by 50%, and print the watermark in the helvetica font in the upper left corner. The processed image is named "Resized-original file name"

Open gedit or leafpad, input the script content, and save it as imagezoom. sh. I saved it on the desktop.

Then

# Chmod + x ~ /Desktop/imagezoom. sh

To facilitate the call, I copied the script to the/bin directory, so that I can use this command in any image folder in the future.

# Sudo cp ~ /Desktop/imagezoom. sh/bin

Let's see the watermark effect.

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.