ImageMagick is called in a program (Linux environment, JSP, PHP)

Source: Internet
Author: User
Tags imagemagick

Recently, when the image format is CMYK, the Image Upload browser cannot display the image normally, and the scaling of the image turns into a black screen,

Later, Google found that ImageMagick has powerful functions. you can install ImageMagick in two ways: 1) directly compile and install it with PHP and call it in the program; 2) directly install it and call system commands.

For simplicity, we have adopted 2nd types and directly used PHP or JSP to call the convert command to convert images from CMYK format to RGB format:

Convert. php
<? PHP
Exec ("/usr/local/bin/convert-colorspace RGB/mnt/SMB/proimg_original/img_u/shop_img/89/cs01831/logs/mnt/SMB/proimg_original/img_u/shop_img /89/cs01831/sregist_1259723804077.jpg ");
?>
PHP convert OK !!

Convert. jsp

<%
Process Objective C ("/usr/local/bin/convert-colorspace RGB/mnt/SMB/proimg_original/img_u/shop_img/89/cs01831/logs/mnt/SMB/proimg_original/img_u /shop_img/89/cs01831/sregist_1259729434254.jpg ");
%>
JSP convert OK!

 

At the same time, a simple Java function is provided to facilitate integration in Java:
Public static Boolean cmyk2rgb (string file ){
File d = new file (File );
If (D. isdirectory ()){
Try {
String [] commands = {"/bin/sh", "-c", "/usr/local/bin/convert-colorspace RGB" + file + "" + file };
Process = runtime.getruntime(cmd.exe C (commands );
Process. waitfor ();
Return true;
} Catch (exception e ){
E. printstacktrace ();
Return false;
}
}
Return true;
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.