使用ImageMagick处理图片
命令格式
1 | convert -auto-orient -strip -compress JPEG2000 -quality 50 -resize 50% 1.jpg 2.jpg |
参数说明
- -auto-orient
adjusts an image so that its orientation is suitable for viewing (i.e. top-left orientation).
根据图片旋转方向自动扶正
- -strip
strip the image of any profiles, comments or these PNG chunks: bKGD,cHRM,EXIF,gAMA,iCCP,iTXt,sRGB,tEXt,zCCP,zTXt,date.
清除图片档案信息,如EXIF
- -compress
Use pixel compression specified by type when writing the image.
Choices are:
None
,BZip
,Fax
,Group4
,JPEG
,JPEG2000
,Lossless
,LZW
,RLE
orZip
.
指定图片压缩格式
- -quality
JPEG/MIFF/PNG compression level.
图片压缩质量,数值越高越清晰
- -resize
Resize an image.
改变图片尺寸
size | General description (actual behavior can vary for different options and settings) |
---|---|
scale% | Height and width both scaled by specified percentage. 宽高等比例缩放 |
scale-x%xscale-y% | Height and width individually scaled by specified percentages. (Only one % symbol needed.) 分别指定缩放比例宽高 |
width | Width given, height automagically selected to preserve aspect ratio. |
xheight | Height given, width automagically selected to preserve aspect ratio. |
widthxheight | Maximum values of height and width given, aspect ratio preserved. |
widthxheight^ | Minimum values of width and height given, aspect ratio preserved. |
widthxheight! | Width and height emphatically given, original aspect ratio ignored. |
widthxheight> | Shrinks an image with dimension(s) larger than the corresponding width and/or height argument(s). |
widthxheight< | Enlarges an image with dimension(s) smaller than the corresponding width and/or height argument(s). |
area@ | Resize image to have specified area in pixels. Aspect ratio is preserved. |
x:y | Here x and y denotes an aspect ratio (e.g. 3:2 = 1.5). |
{size}{offset} | Specifying the offset (default is +0+0). Below, {size} refers to any of the forms above. |
{size}{+-}x{+-}y | Horizontal and vertical offsets x and y, specified in pixels. Signs are required for both. Offsets are affected by ‑gravity setting. Offsets are not affected by % or other size operators. |