ImageMagick jmagick 安装

在安装ImageMagick之前,请检查下面包已经安装

tiff-3.9.5.tar.gz         (rpm -qa|grep libtiff检查是否已经安装)

libpng-1.2.46.tar.gz     (rpm -qa|grep libpng检查是否已经安装)

jpegsrc.v6b.tar.gz       (rpm -qa|grep libjpeg检查是否已经安装)

freetype-2.3.9.tar.bz2   (rpm -qa|grep freetype检查是否已经安装)

libjpeg-devel

    下载地址 http://pkgs.org/download/libjpeg-devel

----tiff-3.8.2.tar.gz   支持tif文件  http://www.linuxfromscratch.org/blfs/view/6.3/general/libtiff.html

----jpegsrc.v6b.tar.gz  支持jpg    或jpegsrc.v8b.tar.gz版本也可 http://www.ijg.org/files/jpegsrc.v6b.tar.gz

----zlib-1.2.6.tar.gz  支持PNG24 

----libpng-1.4.10.tar.gz  支持PNG  或 libpng-1.4.3.tar.gz版本也可 http://sourceforge.net/projects/libpng/

----jasper-1.900.1.zip   支持JPEG2000
----freetype-2.4.4.tar.gz  支持字体

 

wget http://downloads.jmagick.org/6.4.0/ImageMagick-6.4.0-0.tar.gz,

http://downloads.jmagick.org/6.4.0/jmagick-6.4.0-src.tar.gz

 

 

(1)安装tiff-3.8.2

tar –zxvf tiff-3.8.2.tar.gz

cd tiff-3.8.2

./configure

make

make install

make check

 

 

2)安装jpegsrc.v6b.tar.gz

 tar -zxvf jpegsrc.v6b.tar.gz

./configure

make && make install

# ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static

# make

# make install

 

3)安装zlib-1.2.6.tar.gz

tar -xzvf zlib-1.2.5.tar.gz 
cd zlib-1.2.5
./configure
make
make install

(4)安装libpng-1.4.10.tar.gz

tar -zxvf libpng-1.4.10.tar.gz

cd libpng-1.4.10

./configure

make

make install

makeckeck

  

5)安装jasper包,安装后才能处理JPEG2000格式图片
unzip jasper-1.900.1.zip   
cd jasper-1.900.1  
CFLAGS=-fPIC  ./configure   
make CFLAGS=-fPIC   
make  CFLAGS=-fPIC install   

6)安装freetype

tar -zxvf freetype-2.1.10.tar.gz

cd freetype-2.1.10

./configure
make
make install

 

7)安装ImageMagick

tar -zxvf ImageMagick.tar.gz

cd ImageMagick-6.7.6-1

./configure -prefix=/usr/local/ImageMagick

make

make install

make check (会报错,不用理会)

测试

convert  -resize 100x100 111.jpg 11.jpg

convert -resize 100x200 22.jpg(图片路径) 11.jpg(缩放后存放路径) 图片按比例缩放

 

8)安装Jmagick

tar -zxvf JMagick-6.2.6-0.tar.gz
cd JMagick-6.2.6-0
./configure -prefix=/usr/local/Jmagick -with-magick-inc-dir=/usr/local/ImageMagick/include

如果出现错误:Unable to find ImageMagick header files,使用下面语句:

 

./configure -prefix=/usr/local/Jmagick -with-magick-inc-dir=/usr/local/ImageMagick/include/ImageMagick

6.2.4版本的include文件夹和6.4.0的文件夹路径不同造成的,大家安装的时候可以先检查一下include路径下的东西再进行该步骤。

make

make install

 

export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOMR/bin:/usr/local/ImageMagick/bin/

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/Jmagick/lib:/usr/local/ImageMagick/lib

export CLASSPATH=$CLASSPATH:/usr/local/Jmagick/lib

 

//测试类

/usr/local/Jmagick/lib jar 放入 测试test文件夹

java -Djava.ext.dirs=./test/  test.JmagickTest 111.jpg 111_s.jpg

 

 测试类代码

package test;
import java.awt.Rectangle;
import java.io.File;
import magick.ImageInfo;
import magick.MagickException;
import magick.MagickImage;

public class JmagickTest {

 static {
  System.setProperty("jmagick.systemclassloader", "no");
 }
 
 public static void main(String[] args){
  
  if(null==args||args.length<2){
   System.out.println("please input srcImage destImage");
  }
  System.out.println(System.getProperty("java.library.path")); 
  
  System.out.println("srcImage:"+args[0]);
  System.out.println("destImage:"+args[1]);
  try {
   createThumbnail(args[0],args[1],100,100);

   System.out.println("compled...");
  } catch (MagickException e) {
   e.printStackTrace();
  }
 }

 /**
     * 图片缩放
     * */
 public static void createThumbnail(String srcImage, String destImage,
   int width, int height) throws MagickException {
  ImageInfo info = null;
  MagickImage image = null;
  MagickImage scaled = null;
  try {
   String file = srcImage;
   File f = new File(file);
   System.out.println("--f.exists()-->"+f.exists());
   info = new ImageInfo(file);
   image = new MagickImage(info);
   scaled = image.scaleImage(width, height);
   String slogoName = destImage;
   scaled.setFileName(slogoName);
   scaled.writeImage(info);

  } finally {
   if (scaled != null) {
    scaled.destroyImages();
   }
  }
 }
 
}

 

http://downloads.jmagick.org/6.4.0/ImageMagick-6.4.0-0.tar.gz

http://downloads.jmagick.org/6.4.0/jmagick-6.4.0-src.tar.gz

http://www.ijg.org/

http://prdownloads.sourceforge.net/libpng/libpng-1.6.10.tar.gz?download

 

libjpeg-devel

    下载地址 http://pkgs.org/download/libjpeg-devel

 

./configure --prefix=/usr/local/jmagick --with-java-home=/usr/local/jdk1.6.0_31 --enable-diagnostic --with-magick-home=/usr/local/ImageMagick --with-magick-inc-dir=/usr/local/ImageMagick/include/ImageMagick-6

 

http://hi.baidu.com/thinkingjava/item/55ead6b5e64ac477254b09a0

 

http://blog.csdn.net/shixing_11/article/details/6938396

 

http://elf8848.iteye.com/blog/455675

http://hi.baidu.com/thinkingjava/item/55ead6b5e64ac477254b09a0

 

 

1. 下载ImageMagick-6.4.0-0.tar.gz from 
     wget http://downloads.jmagick.org/6.4.0/ImageMagick-6.4.0-0.tar.gz,
2.  tar -xzvf ImageMagick-6.4.0-0.tar.gz
3.  mkdir /usr/local/imagemagick
4.  cd ImageMagick-6.4.0-0
5.  ./configure --prefix=/usr/local/imagemagick/
6.  先make,  然后make install, 再vi /etc/profile, 在最后添加: export $PATH=$PATH:/usr/local/imagemagick/bin

以上安装好之后使用以下方法校验是否安装成功:check: convert 1.jpg -resize 50% 11.jpg

(三)安装JMagick,最好保证ImageMagick和JMagic版本一致

1.  下载jmagick from http://downloads.jmagick.org/6.4.0/jmagick-6.4.0-src.tar.gz
2.   tar -xzvf jmagick-6.4.0-src.tar.gz
3.   cd jmagick-6.4.0-src
4.   ./configure
5.   make, make install
6.   cd lib
#so文件必须放在/usr/lib/ ,否则 java找不到.so库文件
7.   cp *.so /usr/lib/  (我试过,只放一个so,貌似也可以,但是只是简单测试,可能复杂的需要全面)
#把so库文件路径加载到配置文件
8.   vi /etc/ld.so.conf, add: /usr/local/imagemagick/lib
9.   ldconfig #加载至库文件缓存

(四)测试代码:

package com.xingleilee;

import java.awt.Dimension;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import magick.ImageInfo;
import magick.MagickImage;

public class Test {

static {
// 不能漏掉这个,不然jmagick.jar的路径找不到
System.setProperty("jmagick.systemclassloader", "no");
}

/**
* 压缩图片

* @param filePath
* 源文件路径
* @param toPath
* 缩略图路径
*/
/**
* @param filePath
* @param toPath
* @throws Exception
*/
public static void createThumbnail(String filePath, String toPath)
throws Exception {
ImageInfo info = null;
MagickImage image = null;
Dimension imageDim = null;
MagickImage scaled = null;
try {
info = new ImageInfo(filePath);
image = new MagickImage(info);
imageDim = image.getDimension();
int wideth = imageDim.width;
int height = imageDim.height;

height = height/2;
wideth = wideth/2;

scaled = image.scaleImage(wideth, height);// 小图片文件的大小.
scaled.setFileName(toPath);
scaled.writeImage(info);
} catch (Exception e) {
System.out.println(filePath + "压缩 excpeiton");
e.printStackTrace();
} finally {
if (image != null) {
image.destroyImages();
}
if (scaled != null) {
scaled.destroyImages();
}
}
}

/**
* @param args
*/
public static void main(String[] args) throws Exception {

String srcFile1 = "/home/xingleilee/Downloads/images/1.jpg";
String destFile1 = "/home/xingleilee/Downloads/images/";
String destFile11 = "/home/xingleilee/Downloads/images_dest/";

//start:2012-06-17 22:49:18
//end:2012-06-17 22:53:38

System.out.println("start:"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()));
for (int i = 0; i < 1000; i++) {
createThumbnail(destFile1 + i + "_dest.jpg", destFile11 + i + "_dest.jpg");
}

System.out.println("end:"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()));
}

}

posted @ 2014-04-24 17:25  jhhu  阅读(787)  评论(0编辑  收藏  举报