用Java的ImageIO处理一个大于15M的JPG文件,内存溢出。

于是寻求新的解决方案,用ImageMagicK,发现处理图片速度不令人满意,于是切换至GraphicsMagicK,如下是总结。

GraphicsMagick is a fork of ImageMagick. GraphicsMagick has a number of advantages compared to ImageMagick, the most prominent is it's superior performance.”  -from im4java development guide.

如下是快速的总结:

GraphicsMagick(gm)是ImageMagick(im)派生出来的,性能好。

gm和im都需要安装依赖的库,才能处理如jpeg,png图片。

依赖的库有:zlib-1.2.8.tar.gz;libpng-1.6.23.tar.gz;jpegsrc.v9b.tar.gz, 需要首先安装。

ImageMagick安装直接可以用yum安装,如 list|grep -i imagemagick

GraphicsMagick安装需要本地编译安装,首先执行./configure 看看最后有没有png, jpeg, zlib.(重要)

GraphicsMagick与ImageMagick的安装相互独立,但依赖的包相同。

性能上,15Mjpg文件resize,gm快~20%(4U, 4G), 而在一台性能较差的虚拟机gm要比im快6倍(2U,1G),

图片越大,resize的尺寸越大,性能差别越明显。机器配置相差越大,性能差别越大。

性能测试对比

在一台2U1G VirtualBox Linux下resize一个15M的jpg图片。分别用gm和im进行操作,然后对比。

[root@testserver image]# uname -a
Linux testserver 2.6.32-431.el6.i686 #1 SMP Fri Nov 22 00:26:36 UTC 2013 i686 i686 i386 GNU/Linux

[root@testserver image]# free -m
             total       used       free     shared    buffers     cached
Mem:          1178        458        719          0         17        302
-/+ buffers/cache:        138       1039
Swap:         2015        137       1878
[root@testserver image]# gm identify test-bigjpg.jpg
test-bigjpg.jpg JPEG 9864x13703+0+0 DirectClass 8-bit 14.8Mi 0.000u 0:01

resize 操作对比:
[root@testserver image]# ./test.sh test-bigjpg.jpg 2048
elapsed 25s using gm
elapsed 154s using im

Identify -verbose 操作对比:

[root@testserver image]# identify -verbose 1464755573477_45.jpg
Image: 1464755573477_45.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Class: DirectClass
  Geometry: 13925x6459+0+0
  Resolution: 200x200
  Print size: 69.625x32.295
  Units: PixelsPerInch
  Type: ColorSeparation
  Endianess: Undefined
  Colorspace: CMYK
  Depth: 8-bit
  .....//此处省略
  User time: 5.940u
  Elapsed time: 0:34.689
  Version: ImageMagick 6.7.2-7 2016-05-09 Q16 http://www.imagemagick.org
[root@testserver image]# gm identify -verbose 1464755573477_45.jpg
Image: 1464755573477_45.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Geometry: 13925x6459
  Class: DirectClass
  Type: color separated
  Depth: 8 bits-per-pixel component
  ... //此处省略
  User Time: 6.580u
  Elapsed Time: 0:08
  Pixels Per Second: 11.8Mi

附上测试脚本的代码:

#!/bin/sh
starttime=`date '+%s'`
gm convert $1 -resize $2 $1.resize$2.jpg
stoptime=`date '+%s'`
echo elapsed `expr $stoptime - $starttime`s using gm starttime=`date '+%s'`
convert $1 -resize $2 $1.resize$2.jpg
stoptime=`date '+%s'`
echo elapsed `expr $stoptime - $starttime`s using im

Im4java

Im4java同时支持GM 和 IM

With im4java, you have three options if you want to use GraphicsMagick:

  • use GraphicsMagick explicitely, passing the command at object-creation: GraphicsMagickCmd cmd = new GraphicsMagickCmd("convert");.
  • use GraphicsMagick explicitely, using wrapper classes: ConvertCmd cmd = new ConvertCmd(true);.
  • decide at runtime: setting the system-property im4java.useGM to true will select GraphicsMagick at runtime. You can use this feature to compare the results and timings of both toolsets, provided that the commandline is compatible.

Reference:

GraphicsMagick: http://www.graphicsmagick.org/

ImageMagick:http://www.imagemagick.org/script/index.php

Delegatge lib: ftp://ftp.graphicsmagick.org/pub/GraphicsMagick/delegates/

图片处理GraphicsMagick & ImageMagick的更多相关文章

  1. Node.js 引用 gm 包错误 Error: Could not execute GraphicsMagick/ImageMagick

    今天在学习前后台图像剪切时,下载了有图片剪切瑞士军刀之称的 GraphicsMagick. 给 gm.exe 配置了环境变量,在 npm 下好了 gm 的模块,但是运行却出现了错误. 错误如图: [E ...

  2. 使用GraphicsMagick/ImageMagick批量对图片瘦身

    GrahpicsMagick: find . -iname "*.jpg" -exec gm convert -strip +profile "*" -qual ...

  3. 图片处理服务 ImageMagick 的安装和使用

    简介 该文章使用目前官方最新版本7.0.8,这里只记录下Windows系统下的安装. 官方网站:http://www.imagemagick.org/script/index.php. ImageMa ...

  4. 图片工具GraphicsMagick的安装配置与基本使用

    本文使用GraphicsMagick的版本为1.3.18 (Released March 9, 2013). 1.简介 GraphicsMagick是一个短小精悍的的图片处理工具和库集合.对于Java ...

  5. GraphicsMagick / ImageMagick缺少lib报错no decode delegate for this image format

    下载相应的lib,编译安装就行了 cd ~ #下载包 wget http://www.imagemagick.org/download/delegates/zlib-1.2.7.tar.gz wget ...

  6. 【图片处理】ImageMagick, gm

    ImageMagick: Convert, Edit, Or Compose Bitmap Images http://www.imagemagick.org/script/binary-releas ...

  7. Linux图片查看软件ImageMagick安装

    在Linux中查看图片,这个需求是非常常见的.总不至于在集群中生成个图片,随便看下效果,也要用filezilla.winscp之类的远程文件传输工具导过来导过去吧,这样效率太低. Linux图片查看常 ...

  8. ImageMagick简介、GraphicsMagick、命令行使用示例

    http://elf8848.iteye.com/blog/382528 ImageMagick资料 ------------------------------------------------- ...

  9. ImageMagick资料

    ImageMagick资料 ---------------------------------------------------------------------------- ImageMagi ...

随机推荐

  1. 安装KB3132372补丁后,WIN10中IE内核加载flash崩溃

    今天(2015年12月30日)突然很多人反馈在WIN10上IE内核的PC端应用崩溃.经过一番查找,最终定位到问题.WIN10今天发布了新的补丁KB3132372,64位系统更新该补丁后,打开IE内核的 ...

  2. Unity3D LuaBundleLoader(基于cslua)

    说明:异步加载lua的bundle,会优先加载cache目录下bundle(一般更新的资源都在cache下) using System; using UnityEngine; using System ...

  3. [Android] Android统计Apk , jar包方法数

    reference to : http://www.jianshu.com/p/61e8f803e0d1 Android在开发过程中,随着引用的库以及业务的增多,不可避免的会出现64K limit问题 ...

  4. DIV+CSS 清除浮动方法总结

    DIV+CSS 清除浮动是页面布局中常见的问题,相信各位高手也都有自己的方法,今天在这里对常见的几种方法进行总结(PS:谈不上是原创,这里是我自己做的归纳总结,也是我自己内化的过程),希望对您能够有所 ...

  5. 【学习笔记】ES6标准入门

    这里简要记录一下对自己感触比较深的几个知识点,将核心的应用投放于实际的项目之中,提供代码的可维护性. 一.let和const { // let声明的变量只在let命令所在的代码块内有效 let a = ...

  6. phpcms调用一个指定的栏目的url和栏目名称

    {$CATEGORY[$catid]['url']} 指定栏目URL代码 {$CATEGORY[$catid]['catname']} 指定栏目名称代码 {$CATEGORYS[41]['url']} ...

  7. 【C#】 知乎用户网络爬虫

    目的 由一个种子用户出发,抓取相关的关注者和被关注者,然后再延伸开抓取更多的相关用户,以便后期进行数据分析. 拓扑图 开发工具 编程语言:C# 数据库:SqlServer 2008 R2 程序架构 流 ...

  8. 8-06循环结构WHILE

    WHILE 循环语句可以根据某些条件重复执行一条SQL语句或一个语句块. 语句: WHILE(条件) BEGIN 语句或语句块 END 程序调试: ALT+F5启动调试 F9切换断点  F10遂过程, ...

  9. Knockout.js随手记(5)

    以列表方式呈现数据  处理以数组形式储存的多条数据,要先认识foreach.在ViewModel定义一个JavaScript Array或是ko.observableArray() (observab ...

  10. 字符串的replace()方法隐藏着什么不可告人秘密?

    最近在做JS算法项目时发现一个令我匪夷所思的问题, 这里想记录一下问题. 首先介绍一下字符串replace()方法的基本用法. replace() 方法使用一个替换值(replacement)替换掉一 ...