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.