After various Collection on the Internet, we finally got it done. Record that sudo needs to be used for root permission in some places:
(1) ensure that the system has installed the following packages:
Rpm-Q libjpeg-devel libpng-devel LibTIFF-devel libungif-devel Perl-CPAN Perl make gcc
Or directly use the following command to install
Yum install libjpeg
Yum install libjpeg-devel
Yum install libpng
Yum install libpng-devel
Yum install LibTIFF
Yum install LibTIFF-devel
Yum install libungif
Yum install libungif-devel
Yum install Perl-CPAN
(For example, if Perl-CPAN is not installed, the following error will be reported: can't locate extutils/makemaker. pm)
(2) install ImageMagick. It is best to ensure that the ImageMagick and jmagic versions are consistent.
1. Download 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. First make, then make install, then VI/etc/profile, add: export $ Path = $ path:/usr/local/ImageMagick/bin at the end.
Check whether the installation is successful by using the following method: Check: Convert 1.jpg-resize 50% 11.jpg
(3) install jmagick. It is best to ensure that the ImageMagick and jmagic versions are consistent.
1. Download 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
# The so file must be stored in/usr/lib/; otherwise, the. So library file cannot be found in Java.
7. Cp *. So/usr/lib)
# Load the so library file path to the configuration file
8. VI/etc/lD. So. conf, add:/usr/local/ImageMagick/lib
9. ldconfig # load to the Library File Cache
(4) test code:
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 {
// This cannot be missed, or the jmagick. Jar path cannot be found.
System. setproperty ("jmagick. systemclassloader", "no ");
}
/**
* Compressing Images
*
* @ Param filepath
* Source File Path
* @ Param topath
* Thumbnail path
*/
/**
* @ 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); // the size of the small image file.
Scaled. setfilename (topath );
Scaled. writeimage (Info );
} Catch (exception e ){
System. Out. println (filepath + "compressed 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: 22:49:18
// End: 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 ()));
}
}