cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco 3.4 and ImageMagick 6.6.7 (on Windows) - SOLUTION

easypress
Champ in-the-making
Champ in-the-making
Problem:
After upgrading from ImageMagick 6.3.6 (the version bundled with Alf 3.4c) to 6.6.7 all ImageMagick operations fail with "Magick: no decode delegate for this image format" message

Initial env:
Out of the box Alfresco 3.4c install on Windows XP - all works fine, image conversions (jpeg to gif thumbnail and jpeg to jpeg resize) execute correctly

Changes:
a) Install ImageMagick 6.6.7-1-Q16
b) rename convert.exe to imconvert.exe
c) change "img.root=c:/ImageMagick-6.6.7-Q16" and "img.exe =${img.root}/imconvert" in alfresco-global.properties

Analysis:
The code within Alfresco that executes imconvert can be reduced to


package com.easypress.alfresco.repo.content.transform.magick;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;

import org.alfresco.util.exec.RuntimeExec.InputStreamReaderThread;

public class ImageMagickContentTransformerWorkerTest {
  private static final String IMG_ROOT = "c:/ImageMagick-6.6.7-Q16";
  private static final String IMG_DYN  = IMG_ROOT;
  private static final String IMG_EXE  = IMG_ROOT + "/imconvert";
 
  public static void main(String[] args) {
    String[] commandToExecute = new String[] {
      IMG_EXE,
      "c:/temp/ImageMagickContentTransformerWorker_source_test.jpg[0]",
      "-thumbnail",
      "50%",
      "c:/temp/ImageMagickContentTransformerWorker_output_test.jpg"};
    String[] processProperties = new String[] {
      "MAGICK_HOME=" + IMG_ROOT,
      "DYLD_LIBRARY_PATH=" + IMG_DYN,
      "LD_LIBRARY_PATH=" + IMG_DYN};
    File processDirectory = null;

    // Any ONE of these will solve the problem
    // String[] processProperties = null;
    // String[] processProperties = new String[] { "PATH=" + IMG_ROOT};
    // File processDirectory = new File(IMG_ROOT);

    try {
      Process process = Runtime.getRuntime().exec(commandToExecute, processProperties, processDirectory);

      InputStreamReaderThread stdOutGobbler = new InputStreamReaderThread(process.getInputStream(), Charset.defaultCharset());
      InputStreamReaderThread stdErrGobbler = new InputStreamReaderThread(process.getErrorStream(), Charset.defaultCharset());

      stdOutGobbler.start();
      stdErrGobbler.start();

      try {
        process.waitFor();
      } catch (InterruptedException e) {
        stdErrGobbler.addToBuffer(e.toString());
      }

      stdOutGobbler.waitForCompletion();
      stdErrGobbler.waitForCompletion();

      System.out.println("out: " + stdOutGobbler.getBuffer());
      System.out.println("err: " + stdErrGobbler.getBuffer());
    } catch (IOException e) {}
  }
}

and as this can be executed outside of the Alfresco environment and produce exactly the same result the fundamental problem is how Alfresco is setting up the Runtime.exec() method.

The problem is that, for Windows, Alfresco is incompletely replacing the process environment.  While ImageMagick may use the MAGICK_HOME property to locate decoders, it uses the standard Windows process to load decoders and that requires the associated .dll to be either on the path or in the current directory.

Solution:
As given in the code above, there are three possible solutions
a) specify the process directory to be ${img.root} (via the processDirectory property to the RuntimeExec bean)
b) add PATH=${img.root} to the process properties (via the processProperties property map of the RuntimeExec bean)
c) remove the specified process properties and let the process inherit the environment settings (this will only work if ImageMagick has been installed and added to the PATH env)

See http://wiki.alfresco.com/wiki/Alfresco_Subsystems for how to over-ride subsystem configuration

Hope this helps someone!
3 REPLIES 3

dranakan
Champ on-the-rise
Champ on-the-rise
Thank you ! 🙂

The processProperties for Runtime.getRuntime().exec(…) is needed also under Linux.

alekseiv
Champ in-the-making
Champ in-the-making
I have solved this problem by installing ImageMagick version with static libraries.

bmeyns
Champ in-the-making
Champ in-the-making
I have solved this problem by installing ImageMagick version with static libraries.
Indeed, this fixed my problem too!
1. Install the ImageMagick with "static libraries" anywhere on your system.
2. Try to run ImageMagick directly from command line, e.g.:
convert C:\temp\test.jpg -resize 120 C:\temp\test_b.jpg
3. specify the path + exe to your ImageMagick-installation in alfresco-global.properties
img.root=<YourImageMagickInstallationDirectory>
img.exe=${img.root}/convert
and restart Alfresco.