Page 1 of 1

Issue converting PDF to JPG on Heroku

Posted: 2011-08-24T10:12:33-07:00
by ewenjc
I'm using ImageMagick via paperclip from a Ruby on Rails application. In my development environment or terminal window the conversion works perfectly. I'm testing the conversion using the "About Stacks.pdf" that comes on most macs.

using the following command:
convert -resize 2550x3300 -density 450x450 -units pixelsperinch -quality 70 -background white -flatten AboutStacks.pdf output_450.jpg

I get:
Image

the exact commands called by the application are:
[paperclip] identify -format %wx%h '/var/folders/EX/EXX73QxuHMyRzfmtqLOoyU+++TI/-Tmp-/stream20110824-2522-h067yl-0.pdf[0]' 2>/dev/null
[paperclip] convert -density 450x450 -units pixelsperinch -quality 70 -background white -flatten '/var/folders/EX/EXX73QxuHMyRzfmtqLOoyU+++TI/-Tmp-/stream20110824-2522-h067yl-0.pdf[0]' -resize "2550" '/var/folders/EX/EXX73QxuHMyRzfmtqLOoyU+++TI/-Tmp-/stream20110824-2522-h067yl-020110824-2522-12klnpm-0.jpg' 2>/dev/null

but when the same app runs on Heroku (the production server) it produces the following image:
Image

My development machine is running:
Version: ImageMagick 6.7.0-0 2011-06-07 Q16 http://www.imagemagick.org
Heroku is running:
Version: ImageMagick 6.6.0-4 2010-06-01 Q16 http://www.imagemagick.org

Can anyone suggest where I should be looking?
-Ewen

Re: Issue converting PDF to JPG on Heroku

Posted: 2011-08-24T10:43:41-07:00
by fmw42
try proper IM 6 syntax (though old syntax may still work). see http://www.imagemagick.org/Usage/basics/#cmdline

convert -density 450x450 -units pixelsperinch AboutStacks.pdf -resize 2550x3300 -quality 70 -background white -flatten output_450.jpg


If this does not make a difference and if your input image has transparency, then you need to check the device used in your delegates.xml files for ps:alpha. Set it to pngalpha rather than pnmraw. The downside is that it will then only process one page pdf files, but will deal with transparency.

Re: Issue converting PDF to JPG on Heroku

Posted: 2011-08-24T11:36:39-07:00
by ewenjc
Thanks for the ideas. I'm trying to get the convert parameters in the correct order but because the parameters are merged together with a Rails plugin (paperclip) I'm having a hard time, but I'll get there.

In terms of making changes to delegates.xml, on Heroku I can't modify this file. Is there any way I can tell IM this as parameters or can I tell IM to look in a different location for an alternative edited delegates.xml file?

Re: Issue converting PDF to JPG on Heroku

Posted: 2011-08-24T12:56:32-07:00
by fmw42
ewenjc wrote:In terms of making changes to delegates.xml, on Heroku I can't modify this file.

Why not?
ewenjc wrote:Is there any way I can tell IM this as parameters or can I tell IM to look in a different location for an alternative edited delegates.xml file?

That I don't know. But at least you should be able to verify what device is being used in the delegates.xml file. If it is already pngalpha, then there is no need for any change.

You should also check to verify what version of Ghostscript is being used on each system and possibly upgrade if necessary.

gs -- version
GPL Ghostscript 9.02 (2011-03-30)


Are you sure you have Ghostscript installed?

convert -list configure

look at the line starting with DELEGATES. Does it include gs?

Re: Issue converting PDF to JPG on Heroku

Posted: 2011-08-25T03:09:30-07:00
by ewenjc
Heroku does not allow you to run anything command line. But with the tools they supply this is the first time i've needed to. I've asked their support to either send me a copy of delegates.xml or explain how I can view this file.

My local delegates.xml includes the following:
<delegate decode="ps:alpha" stealth="True" command=""/opt/local/bin/gsx" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s""/>

I tried to change it to pnmraw, to see if I could reproduce the problem, but I did not know how to set the other parameters (google didn't help) and it gave me an error.

Google did find an ImageMagick parameter called "with_frozen_path" which I believe will let me specify a different delegates.xml. Extract from http://www.imagemagick.org/script/advan ... lation.php;
--with-frozenpaths
enable frozen delegate paths.
Normally, external program names are substituted into the delegates.xml configuration file without full paths. Specify this option to enable saving full paths to programs using locations determined by configure. This useful for environments where programs are stored under multiple paths, and users may use different PATH settings than the person who builds ImageMagick.


My local gs version is 9.02 (2011-03-30) and the Heroku version is 8.62.

P.S. All my parameters are in the correct order now :) but this did not change the conversion :( but it does look better :)

Re: Issue converting PDF to JPG on Heroku

Posted: 2011-08-25T09:12:15-07:00
by fmw42
<delegate decode="ps:alpha" stealth="True" command=""/opt/local/bin/gsx" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s""/>
Use a text editor to change -sDEVICE=pnmraw to verify if it reproduces your problem on your computer. If so, then get the other system changed to pngalpha, if it is not set that way already

You might upgrade your Ghostscript, if the above is not the issue.

Re: Issue converting PDF to JPG on Heroku

Posted: 2011-08-25T12:14:38-07:00
by ewenjc
On my development machine the conversion works with either setting, so it looks like that's not the issue.

Not sure I can get Heroku to upgrade. I guess I could install locally the same versions of IM and GS that Heroku uses to see what results that produces (assuming I can still access old versions)

Well it will have to wait for a bit as I'm off on vacation tomorrow :)

fmw42, thanks for all you help so far.

Re: Issue converting PDF to JPG on Heroku

Posted: 2011-08-25T14:25:04-07:00
by fmw42
ewenjc wrote:On my development machine the conversion works with either setting, so it looks like that's not the issue.

Not sure I can get Heroku to upgrade. I guess I could install locally the same versions of IM and GS that Heroku uses to see what results that produces (assuming I can still access old versions)

Well it will have to wait for a bit as I'm off on vacation tomorrow :)

fmw42, thanks for all you help so far.

It is looking more and more like a Heroku issue.