Get the size of an image,
Identify test.png
Result:
Test.png PNG 178x15 178x15 + 0 + 0 16-bit pseudo class 65536c 2.28kb
Use 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
Obtain the width and height respectively.
However, it is very troublesome to run this command through runtime in Java. It uses spaces to separate the parameters. It does not think that quotation marks are a parameter, there is also a solution here.
Therefore, it is easy to use the identify test.png command to process the string in Java.
1. Compress an image with a limited height of 60 and a high aspect ratio unchanged. However, if the image is larger than 90, extract the middle section.
Convert source.jpg-resize X60 result_60.jpg
Width and height of the obtained result_60.jpg
If (width> 90 ){
Convert result_60.jpg-gravity center-extent 90x60 result_60.jpg
}
It should be noted that-gravity and-extent used in combination are not normal in 6.2.8, you can choose to use crop
Calculate dx = (width-90)/2
Convert result_60.jpg-crop 90x60 + $ {DX} + 0 result_60.jpg
2. Compress an image. The height and width are limited, and the width and height ratio remain unchanged. You need to cut the image appropriately.
For example, the compression is 60x60, which is a special case. The width and height are exactly the same. If they are different, the computation will be different, but the method is the same.
Width and height of the obtained 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 indicates the width of the image to be captured.
H indicates the height of the image to be captured.
DX, Dy is the starting offset position, starting from the upper left corner
4. puzzles
Horizontal stitching
Convert 1.jpg 2.jpg 3.jpg + append result.jpg
Longitudinal stitching
Convert 1.jpg 2.jpg 3.jpg-append result.jpg
Horizontal + vertical
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-color PNG Compression
Convert-strip-depth 8-colors 256 soure.png result.png
Advpng-z-4 result.png
6. Write on Images
Convert source.jpg-font XXX. TTF-fill red-pointsize 48-annotate + 50 + 50 @text.txt result.jpg
The font XXX. TTF is used, the font is filled in red, the font is 48 pixel, the position (50, 50), and the text is in the text.txt file.
7. Draw a rectangle on the Image
Convert source.jpg fill none-stroke red-strokewidth 3-draw rectangle 50, 50 100,100 result.jpg
There is also a line width of 3, the color is red, from 50 to 100,100 square, not filled
Draw line:-draw line 50, 50 100,100