Alfresco and ImageMagick on OSX

cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco and ImageMagick on OSX

Active Member II
0 5 2,159
Since I migrated away from Windows on my development machine a couple of months back, I've not looked back. One of the main benefits I've found is being able to build software packages locally, and Homebrew makes that easy. Now I can easily grab the latest version of various dependencies such as MySQL and ImageMagick and install them in seconds, just as if I was using yum or apt-get.



However, one problem has plagued me since I started using the Homebrew-installed version of ImageMagick in conjunction with my local Alfresco installs, with errors such as this in the logs

 2012-08-02 10:20:10,547  DEBUG [transform.magick.AbstractImageMagickContentTransformerWorker] [main] org.alfresco.service.cmr.repository.ContentIOException: 07020000 Failed to perform ImageMagick transformation: 

Execution result:

   os:         Mac OS X

   command:    [/usr/local/bin/convert, /Users/wabson/Development/projects/share-extras-2/software/tomcat/temp/Alfresco/ImageMagickContentTransformerWorker_init_source_4067880520213204197.gif[0], /Users/wabson/Development/projects/share-extras-2/software/tomcat/temp/Alfresco/ImageMagickContentTransformerWorker_init_target_7684811633126657147.png]

   succeeded:  true

   exit code:  133

   out:        

   err:        dyld: Symbol not found: __cg_jpeg_resync_to_restart

  Referenced from: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/ImageIO

  Expected in: /usr/local/lib/libjpeg.8.dylib

 in /System/Libra


This frustrated me for a while. It happened every time Alfresco tried to call convert in order to effect an image transform - for instance generating doclib thumbnails - but running the exact same command at a bash prompt worked fine.



Various internet posts all pointed to the environment in which ImageMagick is run as being the cause for such problems. It seemed the environment variable DYLD_LIBRARY_PATH in particular was known to cause problems on OS X, but checking /etc/profile, /etc/bashrc and the custom alfresco.sh script I use to start up Alfresco (included in my Tomcat packages) did not yield any trace of such a variable.



Finally I found a comment in ALF-13452, which led me to check the Spring config within the thirdparty subsystem, responsible for starting up ImageMagick.

   <bean id='transformer.worker.ImageMagick'>

      <property name='mimetypeService'>

         <ref bean='mimetypeService' />

      </property>

      <property name='executer'>

         <bean name='transformer.ImageMagick.Command'>

            <property name='commandsAndArguments'>

               <map>

                  <entry key='.*'>

                     <list>

                        <value>${img.exe}</value>

                        <value>${source}</value>

                        <value>SPLIT:${options}</value>

                        <value>${target}</value>

                     </list>

                  </entry>

               </map>

            </property>

            <property name='processProperties'>

               <map>

                  <entry key='MAGICK_HOME'>

                     <value>${img.root}</value>

                  </entry>

                  <entry key='DYLD_LIBRARY_PATH'>

                     <value>${img.dyn}</value>

                  </entry>

                  <entry key='LD_LIBRARY_PATH'>

                     <value>${img.dyn}</value>

                  </entry>

               </map>

            </property>

            <property name='defaultProperties'>

               <props>

                  <prop key='options'></prop>

               </props>

            </property>

         </bean>

      </property>

     ...


There it was. The subsystem itself was setting up a few environment variables before firing up the external process, and these were defined in processProperties. One was the DYLD_LIBRARY_PATH variable.



The solution was trivial. I copied the Spring config in tomcat/webapps/alfresco/WEB-INF/classes/alfresco/subsystems/thirdparty/default/imagemagick-transform-context.xml into tomcat/shared/classes/alfresco/extension/subsystems/thirdparty/default/default/imagemagick-transform-context.xml as per the subsystems docs on overriding beans, and commented out the offending <entry> element.

mkdir -p tomcat/shared/classes/alfresco/extension/subsystems/thirdparty/default/default/

cp tomcat/webapps/alfresco/WEB-INF/classes/alfresco/subsystems/thirdparty/default/imagemagick-transform-context.xml tomcat/shared/classes/alfresco/extension/subsystems/thirdparty/default/default/

vim tomcat/shared/classes/alfresco/extension/subsystems/thirdparty/default/default/imagemagick-transform-context.xml


The result - image conversions now work perfectly in my local dev environment using the Homebrew-installed version of ImageMagick.
5 Comments
Active Member
For pdf to thumbnail I also had to install ghostscript (brew install ghostscript). Still had an error 'convert: Postscript delegate failed ...'

I was able to solve this with a symbolic link in /usr/bin



sudo ln -s /usr/local/bin/gs /usr/bin
Active Member II
Did you set gs.exe=/usr/local/bin/gs in your alfresco-global.properties? That should also fix the error.
Active Member
Hah, I was about to post a very similar blog post with a very different solution -- namely, re-linking the offending dylibs -- but this is much cleaner and, well, sane. Smiley Happy Thanks, Will!
Active Member
[...] is to configure ImageMagick to ignore a system property that causes intermittent errors on Mac OS, submitted by Will Abson. Copy the file "/alfresco/subsystems/thirdparty/default/imagemagick-transform-context.xml" to [...]
Active Member
[...] For Mac systems, fix the ImageMagick configuration per Will Abson's instructions. [...]