【 XBATU . COM 】    【 MOZICHINA . COM 】    【 2858999 . COM 】


 

Mogrify为图片添加中文水印时显示中文乱码的解决方法

webmaster@李松涛 提交于 周二, 03/01/2016 - 13:34
ImageMagick

ImageMagick软件是程序员专用的、开源的图片处理软件,图片处理功能强大的一塌糊涂,而mogrify是ImageMagick软件包含的众多的命令行工具之一,ImageMagick包含如下的命令行工具:

1. animate
animate an image sequence on any X server.

2. compare
mathematically and visually annotate the difference between an image and its reconstruction.

3. composite
overlap one image over another.

4. conjure
interpret and execute scripts written in the Magick Scripting Language (MSL).

5. convert
convert between image formats as well as resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more.

6. display
display an image or image sequence on any X server.

7. identify
describe the format and characteristics of one or more image files.

8. import
save any visible window on an X server and outputs it as an image file. You can capture a single window, the entire screen, or any rectangular portion of the screen.

9. mogrify
resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more. Mogrify overwrites the original image file, whereas, convert writes to a different image file.

10. montage
create a composite image by combining several separate images. The images are tiled on the composite image optionally adorned with a border, frame, image name, and more.

11. stream
a lightweight tool to stream one or more pixel components of the image or portion of the image to your choice of storage formats. It writes the pixel components as they are read from the input image a row at a time making stream desirable when working with large images or when you require raw pixel components.

想要详细了解、学习ImageMagick,最好的方式是直接访问其官方网站www.imagemagick.org,毕竟那才是真正的本尊,百度搜到的一些相关中文网页,有时难免存在一些过时或者错误。

言归正传,不少朋友用ImageMagick为图片添加中文水印都遇到过水印显示乱码的问题,网上靠谱的解决方法还真不好找,本人最近刚刚解决该问题,于是把方法整理出来,帮助那些需要帮助的朋友们。

以下是本人用mogrify为图片添加中文水印的命令,该命令可以正常工作。
mogrify -font '/usr/share/fonts/truetype/wqy/wqy-microhei.ttc' -fill green -pointsize 20 -gravity SouthEast -draw 'text 10,10 "赛因拔都 XBATU.COM"' IMG_20160223_214136_250x427.png

对以上命令的其他内容不做过多解释,重点是:
'/usr/share/fonts/truetype/wqy/wqy-microhei.ttc' 必须是mogrify可找到的、可读的中文字体文件,注意必须是中文字体文件,本人用的是ubuntu14.04, 中文字体文件为'/usr/share/fonts/truetype/wqy/wqy-microhei.ttc'。

所以,解决方法为:朋友们请自行确认自己的操作系统上当前可用的中文字体文件,并设置为命令中-font 参数的值即可!

搞定!


【 XBATU . COM 】    【 MOZICHINA . COM 】    【 2858999 . COM 】