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 image scaling turns into a black screen. Later, google found that imagemagick is very powerful and can be installed in two ways. 1) directly compile and install with php and call it in the program; 2) directly install 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

Copy to ClipboardReference: [www.bkjia.com] <? 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

Copy to ClipboardReference: [www.bkjia.com] <%
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:

Copy to ClipboardReference: [www.bkjia.com] 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 process = runtime.getruntime(cmd.exe c (commands );
Process. waitFor ();
Return true;
} Catch (Exception e ){
E. printStackTrace ();
Return false;
}
}
Return true;
}

Source: http://www.cnblogs.com/coffee_cn/

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.