Convert image processing tool for Linux

Source: Internet
Author: User

Get the size of a picture,

Identify Test.png

The result is:

Test.png png 178x15 178x15+0+0 16-bit pseudoclass 65536c 2.28kb

Using the shell

Identify Test.png | Cut-d '-F 3 | cut-d ' x '-F 1

Identify Test.png | Cut-d '-F 3 | cut-d ' X '-F 2

Get the width and height separately

However, it is cumbersome to run this command through runtime in Java, which uses a space to split the parameters, it does not think that quotation marks are caused by a parameter, this also has a solution, here does not say.

So, with identify test.png This command, get the string to be handled in Java way, is also very simple.

1, compress a picture, the limit height is 60, the width and height ratio is unchanged, but if the width is greater than 90, intercept the middle section

Convert Source.jpg-resize x60 result_60.jpg

Get the width and height of result_60.jpg

if (W > 90) {

Convert result_60.jpg-gravity center-extent 90x60 result_60.jpg

}

Note here that-gravity and-extent are not normal for use in 6.2.8 versions, and can be selected with crop

Calculate dx = (width -90)/2

Convert Result_60.jpg-crop 90x60+${dx}+0 result_60.jpg

2, compression of a picture, limit the height and width, width and height of the same, the need for appropriate cuts

For example: Compression to 60x60, this is a special case, the width is exactly the same, if different, the calculation will vary, but the same way.

Get the width and height of source.jpg

if (width > height) {

Convert source.jpg-resize x60-gravity center-extent 60x60 result_60.jpg

}

else{

Convert source.jpg-resize 60x-gravity center-extent 60x60 result_60.jpg

}

3.

Convert Result_60.jpg-crop wxh+dx+dy result_60.jpg

W is the width of the image to be captured

H is the height of the image to be captured

Dx,dy is the offset position at which to start the intercept, with the upper left corner as the origin.

4. Puzzles

Horizontal stitching

Convert 1.jpg 2.jpg 3.jpg +append result.jpg

Vertical stitching

Convert 1.jpg 2.jpg 3.jpg-append result.jpg

Horizontal + Portrait

convert /( 1.jpg 2.jpg 3.jpg +append /) /
/( 4.jpg 5.jpg 6.jpg +append /) /
/( 7.jpg 8.jpg 9.jpg +append /) /
-append result.jpg

5、256色png压缩
convert -strip -depth 8 -colors 256 soure.png result.png
advpng -z -4 result.png

6、图片上写字
convert source.jpg -font xxx.ttf -fill red -pointsize 48 -annotate +50+50 @text.txt result.jpg
使用字体xxx.ttf, 字体用红色填充,字体48pixel, 位置(50,50), 文字在text.txt文件中

7、图片上画长方形
convert source.jpg fill none -stroke red -strokewidth 3 -draw rectangle 50,50 100,100 result.jpg
还一个线宽为3,颜色为红色,从50,50到100,100的正方形,不填充
画线为 -draw line 50,50 100,100 
相关链接:

1. http://dikar.iteye.com/blog/1576056

2. http://www.linuxbyte.org/linux-convert-mini-howto.html

3. http://www.cnblogs.com/chenwenbiao/archive/2011/07/25/2116152.html

4. http://wiki.klniu.com/zh/Linux常用命令或工具集 (10)

Convert image processing tool for Linux

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.