简体   繁体   中英

Azure : Image Magick gives 0kb output?

I have integrated Image magick with a Java WebApp and have deployed it on Azure App Service. On azure , I am getting 0kb as output image for a image while the same image gets converted fine on my local machine. I am using im4java for integration with Image Magick. Below is the code:

public void compressImage(String imageSource, String destinationPath) throws IOException, InterruptedException,
        IM4JavaException {
    ConvertCmd cmd = getCommand();
    // create the operation, add images and operators/options
    IMOperation op = new IMOperation();
    op.strip();
    op.interlace();
    op.addRawArgs(compressionRawArguments);
    op.gaussianBlur(compressionGaussianBlur);
    op.quality(compressedImageQuality);
    op.addImage(imageSource); // source file
    op.addImage(destinationPath); // destination file
    // execute the operation

    cmd.run(op);
}

Both imageSource and destination are temp files created using java. I have checked that imageSource file has correct size but after running this code, the destination file is always 0 Kb.

Please advise what could I be doing wrong?

Answering my own question so that It might be helpful for fellow developers who might face this problem.

Azure App Service normally has Windows Server VMs. You can check the OS of your server in web container logs.

Image Magick for windows does not allow conversion of remote http image urls while for Unix System, it allows so. My Local machine is MAC So it was working correctly on my local system.

2 Solutions to this problem that I found:

  1. Either you use a linux VM on Azure

  2. In your application, download the image URL to a temp file and supply the absolute path of that temp file to image magick for conversion.

I have tried both and are both working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM