1

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?

Peter Pan
  • 23,476
  • 4
  • 25
  • 43
  • Did you install or upload ImageMagick on your webapp? Did you try to run the ImageMagick cmdline via Kudu Console if installed or uploaded im? – Peter Pan Mar 04 '16 at 05:47
  • Sorry for the late reply! It Seems since on azure app service, They are Windows Server VMs while my local machine is mac and Image magick for windows doesnt support conversion of remote http image urls so that was the reason I was getting 0Kb Image. – Inderdeep Singh Mar 23 '16 at 10:59
  • It seems that you have been resolved the issue. Thanks for your sharing. – Peter Pan Mar 24 '16 at 02:49

1 Answers1

1

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.