原创内容,转载请注明出处:https://www.myzhenai.com/thread-15494-1-1.html https://www.myzhenai.com.cn/post/1012.html
ImageMagick是一套功能强大、稳定而且免费的工具集和开发包,可以用来读、写和处理超过89种基本格式的图片文件,包括流行的TIFF、JPEG、GIF、 PNG、PDF以及PhotoCD等格式。利用ImageMagick,你可以根据web应用程序的需要动态生成图片, 还可以对一个(或一组)图片进行改变大小、旋转、锐化、减色或增加特效等操作,并将操作的结果以相同格式或其它格式保存,对图片的操作,即可以通过命令行进行,也可以用C/C++、Perl、Java、PHP、Python或Ruby编程来完成。同时ImageMagick提供了一个高质量的2D工具包,部分支持SVG。现在,ImageMagic的主要精力集中在性能、减少bug以及提供稳定的API和ABI上。
ImageMagick 是一个用来创建、编辑、合成图片的软件。它可以读取、转换、写入多种格式的图片。图片切割、颜色替换、各种效果的应用,图片的旋转、组合,文本,直线, 多边形,椭圆,曲线,附加到图片伸展旋转。ImageMagick是免费软件:全部源码开放,可以自由使用,复制,修改,发布。支持大多数的操作系统。
官方的安装说明是:
建议到ImageMagick的官方主页上下载最新版本的源码包,我下的是ImageMagick-5.5.6.tar.gz,在linux下的安装过程如下:
#tar zxvf ImageMagick-5.5.6.tar.gz #cd ImageMagick-5.5.6 #./configure #make #make install
我使用的安装方法很简单
[RucLinux@localhost ~]$ su root 密码: [root@localhost RucLinux]# yum install ImageMagick* Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile * base: mirrors.stuhome.net * extras: mirrors.grandcloud.cn * updates: mirrors.stuhome.net base | 3.7 kB 00:00 extras | 3.5 kB 00:00 updates | 3.5 kB 00:00 updates/primary_db | 1.3 MB 00:02 Setting up Install Process Package ImageMagick-6.5.4.7-6.el6_2.i686 already installed and latest version Resolving Dependencies --> Running transaction check ---> Package ImageMagick-c++.i686 0:6.5.4.7-6.el6_2 will be installed ---> Package ImageMagick-c++-devel.i686 0:6.5.4.7-6.el6_2 will be installed ---> Package ImageMagick-devel.i686 0:6.5.4.7-6.el6_2 will be installed --> Processing Dependency: libtiff-devel for package: ImageMagick-devel-6.5.4.7-6.el6_2.i686 --> Processing Dependency: lcms-devel for package: ImageMagick-devel-6.5.4.7-6.el6_2.i686 --> Processing Dependency: jasper-devel for package: ImageMagick-devel-6.5.4.7-6.el6_2.i686 --> Processing Dependency: ghostscript-devel for package: ImageMagick-devel-6.5.4.7-6.el6_2.i686 ---> Package ImageMagick-doc.i686 0:6.5.4.7-6.el6_2 will be installed ---> Package ImageMagick-perl.i686 0:6.5.4.7-6.el6_2 will be installed --> Running transaction check ---> Package ghostscript-devel.i686 0:8.70-15.el6_4.1 will be installed ---> Package jasper-devel.i686 0:1.900.1-15.el6_1.1 will be installed ---> Package lcms-devel.i686 0:1.19-1.el6 will be installed ---> Package libtiff-devel.i686 0:3.9.4-9.el6_3 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: ImageMagick-c++ i686 6.5.4.7-6.el6_2 base 142 k ImageMagick-c++-devel i686 6.5.4.7-6.el6_2 base 91 k ImageMagick-devel i686 6.5.4.7-6.el6_2 base 86 k ImageMagick-doc i686 6.5.4.7-6.el6_2 base 3.2 M ImageMagick-perl i686 6.5.4.7-6.el6_2 base 150 k Installing for dependencies: ghostscript-devel i686 8.70-15.el6_4.1 updates 42 k jasper-devel i686 1.900.1-15.el6_1.1 base 374 k lcms-devel i686 1.19-1.el6 base 49 k libtiff-devel i686 3.9.4-9.el6_3 base 468 k Transaction Summary ================================================================================ Install 9 Package(s) Total download size: 4.6 M Installed size: 25 M Is this ok [y/N]: y Downloading Packages: (1/9): ImageMagick-c++-6.5.4.7-6.el6_2.i686.rpm | 142 kB 00:00 (2/9): ImageMagick-c++-devel-6.5.4.7-6.el6_2.i686.rpm | 91 kB 00:00 (3/9): ImageMagick-devel-6.5.4.7-6.el6_2.i686.rpm | 86 kB 00:00 (4/9): ImageMagick-doc-6.5.4.7-6.el6_2.i686.rpm | 3.2 MB 00:06 (5/9): ImageMagick-perl-6.5.4.7-6.el6_2.i686.rpm | 150 kB 00:00 (6/9): ghostscript-devel-8.70-15.el6_4.1.i686.rpm | 42 kB 00:00 (7/9): jasper-devel-1.900.1-15.el6_1.1.i686.rpm | 374 kB 00:00 (8/9): lcms-devel-1.19-1.el6.i686.rpm | 49 kB 00:00 (9/9): libtiff-devel-3.9.4-9.el6_3.i686.rpm | 468 kB 00:00 -------------------------------------------------------------------------------- Total 452 kB/s | 4.6 MB 00:10 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : jasper-devel-1.900.1-15.el6_1.1.i686 1/9 Installing : ghostscript-devel-8.70-15.el6_4.1.i686 2/9 Installing : libtiff-devel-3.9.4-9.el6_3.i686 3/9 Installing : lcms-devel-1.19-1.el6.i686 4/9 Installing : ImageMagick-devel-6.5.4.7-6.el6_2.i686 5/9 Installing : ImageMagick-doc-6.5.4.7-6.el6_2.i686 6/9 Installing : ImageMagick-c++-6.5.4.7-6.el6_2.i686 7/9 Installing : ImageMagick-c++-devel-6.5.4.7-6.el6_2.i686 8/9 Installing : ImageMagick-perl-6.5.4.7-6.el6_2.i686 9/9 Verifying : ImageMagick-perl-6.5.4.7-6.el6_2.i686 1/9 Verifying : lcms-devel-1.19-1.el6.i686 2/9 Verifying : libtiff-devel-3.9.4-9.el6_3.i686 3/9 Verifying : ghostscript-devel-8.70-15.el6_4.1.i686 4/9 Verifying : ImageMagick-devel-6.5.4.7-6.el6_2.i686 5/9 Verifying : ImageMagick-doc-6.5.4.7-6.el6_2.i686 6/9 Verifying : ImageMagick-c++-devel-6.5.4.7-6.el6_2.i686 7/9 Verifying : ImageMagick-c++-6.5.4.7-6.el6_2.i686 8/9 Verifying : jasper-devel-1.900.1-15.el6_1.1.i686 9/9 Installed: ImageMagick-c++.i686 0:6.5.4.7-6.el6_2 ImageMagick-c++-devel.i686 0:6.5.4.7-6.el6_2 ImageMagick-devel.i686 0:6.5.4.7-6.el6_2 ImageMagick-doc.i686 0:6.5.4.7-6.el6_2 ImageMagick-perl.i686 0:6.5.4.7-6.el6_2 Dependency Installed: ghostscript-devel.i686 0:8.70-15.el6_4.1 jasper-devel.i686 0:1.900.1-15.el6_1.1 lcms-devel.i686 0:1.19-1.el6 libtiff-devel.i686 0:3.9.4-9.el6_3 Complete! [root@localhost RucLinux]#
以下内容引用自:https://www.vpsee.com/2009/09/resize-and-watermark-images-in-linux/
先用画图工具制作好一个水印图片 watermark.jpg,然后执行 composite 命令把这个 watermark.jpg 水印加到图片 vpsee.jpg 上,-dissolve 15 是指 watermark.jpg 使用15%的透明附在原图上:
$ composite -gravity northeast -dissolve 15 watermark.jpg vpsee.jpg vpsee.jpg
要事先做个 watermark.jpg 好麻烦,有没有不用 watermark.jpg 直接加水印的方法?有,不过这种方法需要 Linux 系统上已经安装 True 字体(一般来说服务器都没有安装,不建议为了一个水印安装一个硕大的字体),以下命令把 vpsee.com 字符串加到 image.jpg 图片上:
$ mogrify -font /usr/share/fonts/truetype/thai/Purisa.ttf -pointsize 15 \ -verbose -draw "fill black text 5,23 'vpsee.com' \ fill orange text 6,24 'vpsee.com' " image.jpg
可以用下面的 shell script 对某个目录的所有图片加水印,需要注意的是处理带空白字符的文件名很麻烦,所以下面的脚本先处理空白字符,把包含空白字符的文件名用 “_” 字符替代,比如:image 1.jpg 替换成 image_1.jpg:
#!/bin/bash echo "Image watermarking Script" echo "https://www.vpsee.com" echo "" if [ $# -ne 2 ] then echo "usage: ./watermark watermark.jpg picture_directory" echo "" exit fi MARK=$1 PICDIR=$2 for each in $PICDIR/*{.jpg,.jpeg,.png,.JPG,.JPEG,PNG} do mv "$each" `echo $each | tr ' ' '_'`; composite -gravity northeast -dissolve 15.3 $MARK $each $each 2> /dev/null echo "$each: done!" done exit 0
imagemagick 的功能很强大,把上面脚本中的 composite 一行换成下面这行就成了批量给图片改大小了:
$ convert -resize 400 old_image.jpg new_image.jpg
如果想直接把原图改小,用新图片覆盖原图片的话:
$ convert -resize 400 image.jpg image.jpg
sicnature ---------------------------------------------------------------------
I P 地 址: 18.119.122.69
区 域 位 置: 美国马萨诸塞
系 统 信 息:
Original content, please indicate the source:
同福客栈论坛 | 蟒蛇科普 | 海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
没有评论