The method of using shell script to add watermark to the picture under the specified folder under Linux _linux Shell

Source: Internet
Author: User
Tags imagemagick

To implement Linux under the Shell script batch for the specified folder to add a watermark to the picture, first need to install ImageMagick:

Install on CentOS:

Yum Install Imagemagick-y

Install on Debian:

Apt-get Install Imagemagick-y

Script:

#!/bin/bash
for all in/to be processed the picture directory/*{.jpg,.gif}
s= ' du-k $each | awk ' {print '} '
if [$s-gt]; then
  # Convert-quality 80-resize 600x800 $each $each
  composite-gravity southeast-dissolve-/<a "href= con.com/tag/%25e6%25b0%25b4%25e5%258d%25b0/"rel=" external nofollow "onclick=" javascript:tagshow (' watermark '); return false; " > Watermark </a> directory/mark.jpg $each $each 2>/dev/null
  echo "$each: done!"
Fi
done
exit 0

The main is the script, for this we will briefly analyze:

Convert-quality 80-resize 600x800 $each $each

This is a picture shrink.

-quality 80 represents picture quality
600x800 picture size 600 wide X800 high

Do not need to remove the good!

Composite-gravity southeast-dissolve 80/Watermark directory/mark.jpg $each $each 2>/dev/null

This sentence is a watermark of the image

-gravity Southeast Picture Watermark Location South is the South East is the picture of the lower right corner
-dissolve 80 This is to set the transparency of the watermark. The smaller the more transparent.
/watermark Directory/mark.jpg The location of the watermark picture
If [$s-gt 10] to determine the image size is less than 10K of watermark
For all in/to process the picture directory/*{.jpg,.gif} need to add watermark to the directory of the file format

After the file is configured, save as watermark.sh.
And then run it.

Sh./watermark.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.