How to install and use the ImageMagick command in centos

Source: Internet
Author: User
Tags imagemagick centos

Let's first introduce ImageMagick.

ImageMagick (IM) is an open-source free software package that supports the GPL protocol.
It consists of a group of command line tools.
It can be applied to over 100 image formats (including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF ), read, write, edit, and convert operations.
It supports most mainstream operating systems, including UNIX, Mac OS X, and Windows.

IM home page is http://www.imagemagick.org /. You can download its source code or executable files there.
Generally, you can directly download its Windows release. Address: http://www.imagemagick.org/script/binary-releases.php#windows.

There are 6 formats to choose from. If you do not know what you want, I suggest you download the static version of Q16.

Let's take a look at what ImageMagick can do:

1. Rotate, split, and serial numbers in batches

2. auto-crop)


Install Imagemagick

First install Imagemagick

Install on CentOS

Yum install ImageMagick-y

Debian installation

Apt-get install ImageMagick-y

3. Automatic tilt correction)

4. Add tags in batches

5. Batch tagging

6. Add watermarks in batches

7. Batch watermark removal

 

Imagemagick batch compress images to form thumbnails

First, you must install ImageMagick. In linux, this tool is extremely powerful to reduce images in batches.


Command for batch scaling images to a specified size:

For img in 'ls *. jpg '; do convert-sample 25% x25 % $ img thumb-$ img; done
# This command is used to reduce the batch size by 25%.
You can specify only the width or height proportional scaling.
For example, you can specify only the width proportional scaling command:

# For img in 'ls *. jpg '; do convert-sample 200 $ img thumb-$ img; done
Or only specify the height proportional scaling:

# For img in 'ls *. jpg '; do convert-sample x200 $ img thumb-$ img; done
Generate thumbnails for all images in the current directory

For img in 'ls *. jpg 'do convert-sample 25% x25 % $ img thumb-$ img done
Batch scale down the images in the root directory folder. If the width is greater than PX, it will be scaled down; otherwise, it will not move:

For img in 'ls */*. jpg '; do convert-resize "900>" $ img; done

Note:-resize is reduced, and-sample is compressed.
Note: For the sake of insurance, you can copy and back up the image before compressing it, and then uncompress it: for example:

Cp-rf upload/* upload2/


Imagemagick: Batch scale down images and add watermarks

IM has several ways to scale the image. Here I will only talk about the most basic resize command.

Batch processing script

#! /Bin/bash
For each in/The Image folder to process/* images .jpg, .gif}
Do
S = 'Du-k $ each | awk '{print $1 }''
If [$ s-gt 10]; then
Convert-quality 80-resize 600x800 $ each
Composite-gravity southeast-dissolve 80/watermark folder/mark.jpg $ each 2>/dev/null
Echo "$ each: done! "
Fi
Done
Exit 0

The new image generated by this script will overwrite the original

Convert-quality 80-resize 600x800 $ each
This is to narrow down the image-quality 80 represents the image quality, 600 x is the image size wide x High, all produced images are within the range of X.

Composite-gravity southeast-dissolve 80/watermark folder/mark.jpg $ each 2>/dev/null
This sentence adds an image watermark, but the text watermark is not written. -gravity southeast determines the position of the image watermark. south, south, east, and bottom right corner of the image.-dissolve 80 sets the watermark transparency. the smaller the value, the more transparent it is.

$ S-gt 10
This ignores files smaller than 10 kB and prevents watermarks from being added to thumbnails.

If the name of the script you saved is water. sh, run the script.

Sh./water. sh

Related Article

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.