jmagic 的安装与使用

本文提供了一套详细的指南,教你如何在Windows XP系统上安装ImageMagick和JMagick,并确保它们在Tomcat环境下正常工作。包括下载、安装、配置路径等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

平台:winXP
1. 安装ImageMagick(ImageMagick website:http://www.imagemagick.org/script/index.php)
下载并安装ImageMagick。file name: ImageMagick-6.2.6-8-Q16-windows-dll.exe
download address: http://prdownloads.sourceforge.net/imagemagick/ImageMagick-6.2.6-8-Q16-windows-dll.exe?download
安装成功后,

把install path加入系统path(有些版本自己会默认添加),以便能调用dll.保险起见,

然后再把安装目录下的所有dll文件复制到C:\WINDOWS\system32下(因为我出现过只添加路径而不复制这些文件到C:\WINDOWS\system32,程序运行提示出错的情况)

2. 安装JMagick(JMagick website: http://www.yeo.id.au/jmagick/)
下载JMatick。file name: jmagick-6.2.6-win.zip
download address: http://www.yeo.id.au/jmagick/quickload/win-6.2.6/jmagick-6.2.6-win.zip
解压后

把jmagick-6.2.6-win\q16\jmagick.dll copy 到c:\windows\system32目录下,如果程序在运行的时候提示:找不到jmagick路径,用 System.out.println(System.getProperty("java.library.path")). 打印出当前环境的路径,然后再把jmagick.dll 复制到其中的一个路径文件夹中

notes: If you are using Tomcat, or other java applications which have their own classloaders,

方法1: 把jmagick-6.2.6-win\jar\jmagick.jar copy到项目的WEB-INF\lib目录下,然后在服务启动初始化的时 候,System.setProperty("jmagick.systemclassloader","no"); (可以在过滤器的那个类里面加上这句话,也可以自己手动建立一个初始化的serverlet,然后加上这句话)

方法2:简单的方法,把jmagick-6.2.6-win\jar\jmagick.jar 复制到%JAVA_HOME%\jre\lib\ext.就ok了

下面总结下windows + tomcat环境的安装配置

1:下载安装ImageMagick-6.3.4-10-Q16-windows-dll.exe

2:把install path加入系统path,然后把install path下的dll文件复制到C:\WINDOWS\system32

3:下载JMatick。file name:jmagick-6.2.6-win-im-6.2.9.zip

4:把q16目录下的jmagick.dll复制到D:\Tomcat5.0\bin下(D:\tomcat是安装路径)

5:把jar_15目录下的jmagick.jar复制到%JAVA_HOME%\jre\lib\ext.

6:完毕,测试

PS:

web应用如果部署到tomcat下,那么最好在catalina.bat文件中改变如下设置

set JAVA_OPTS=%JAVA_OPTS% -Xms256M -Xmx768M -XX:MaxPermSize=128M -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file="${catalina.base}\conf\logging.properties"

避免heap溢出的问题,参数看你自己的机器而定。( -Xms256M -Xmx768M -XX:MaxPermSize=128M )

下面把jmagick-6.2.6-win-im-6.2.9目录下的说明文档附在这里,注意看他的Getting Started和Notes部分

This archive contains jmagick.dll 6.2.6 compiled against
ImageMagick 6.2.9.

q8 contains jmagick.dll compiled against ImageMagick 6.2.9-Q8
http://www.imagemagick.org/download/binaries/ImageMagick-6.2.9-4-Q8-windows-dll.exe

q16 contains jmagick.dll compiled against ImageMagick 6.2.9-Q16
http://www.imagemagick.org/download/binaries/ImageMagick-6.2.9-4-Q16-windows-dll.exe

It was built with gcc mingw 3.4.2 on Windows 2000 and Sun JDK 1.5.0 release 5.


Getting Started:

1. Install ImageMagick
2. Copy the jmagick.dll corresponding with the Q8 or Q16 ImageMagick you installed to
somewhere in your PATH. I would put it in the same directory as ImageMagick.
3. Put jmagick.jar in your java classpath. If you are using Tomcat, or other java
applications which have their own classloaders, move the jar up to a more global scope.
If you had placed the jar in WEB-INF/lib and reload the webapp, java will attempt to
reload jmagick.dll twice, and it will fail. By moving the jar up, the library will only
be loaded once per jvm lifetime. I place mine in %JAVA_HOME%\jre\lib\ext.

Notes:
-------------------------------------------------------------------------------------------------
If you see exceptions such as UnsatisfiedLinkError, you did one of the above steps incorrectly
or you are not using the JVM/ImageMagick versions you think you are. Have your java code
print out the java.library.path -- System.getProperty("java.library.path"). Check to ensure
that jmagick.dll is in one of those directories.
-------------------------------------------------------------------------------------------------
If you run your java application as a service, any changes to the PATH environment variable will
not be visible to java until you reboot.
-------------------------------------------------------------------------------------------------
This is the first time I have built jmagick.dll using gcc/mingw. Let me know if you have any issues.

Mark Deneen
mdeneen at gmail dot com

---------------------------------------------------------------------------------------------------------------------------------

例子:

/**
* 以正方形比例输出缩放图片
*
* MaxBorderLen : 正方形边长
*/
public void CoutImage4Square(String srcImage, String DestImage, int MaxBorderLen){

System.setProperty("jmagick.systemclassloader","no");

try{

ImageInfo info = new ImageInfo(srcImage);
MagickImage image = new MagickImage(info);

//取长宽
Dimension dim = image.getDimension();
double wImage = dim.getWidth();
double hImage = dim.getHeight();

Boolean bWBig = wImage > hImage? true:false ;

if (bWBig)
{//长大过高
hImage = MaxBorderLen * ( hImage / wImage);
wImage = MaxBorderLen;
}
else
{//反之
wImage = MaxBorderLen * ( wImage / hImage);
hImage = MaxBorderLen;
}

//输出
MagickImage scaled = image.scaleImage((int)wImage, (int)hImage);
scaled.setFileName(DestImage);
scaled.writeImage(info);

}catch(MagickApiException ex){
}catch(MagickException ex){
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值