This entry was posted on Tuesday, October 30th, 2007 at 1:46 pm and is filed under Journal. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Processing Images in Rails - It’s driving me nuts.

So I’m trying to convert a bunch of photos grabbed from a data feed, but It’s just not working in Rails for some reason.

I first tried RMagick, then ImageScience, then using back-ticks to run the command line ImageMagick convert. All of them end up generating corrupt images.

I run the command line from the command prompt and it works fine. I run it from the console, and it still runs fine. It just won’t run from my model.

The command line is:
sudo -u www /usr/local/bin/convert -geometry “1024×768>” -strip -quality 90 o-1.jpg l-1.jpg

I have removed the path for my blog. o-1.jpg is the original photo, l-1.jpg is the large size preview.

The errors I get are:
convert: Premature end of JPEG file o-2.jpg’.
convert: Corrupt JPEG data: premature end of data segment `o-2.jpg’.

It makes a jpg with the bottom half chopped off and all gray.

I’m thinking that Ruby or Rails is running out of memory while processing the image… maybe.. I don’t know.

  1. Karl | October 31st, 2007 at 6:11 am

    have you checked typos yet, I bet its a typo. “I always screw up those mundane details like that.”

  2. Phill Kenoyer | November 2nd, 2007 at 7:46 am

    Nope, not a typo.

    Works at the command line:
    > /usr/local/bin/convert -geometry “1024×768>” -strip -quality 90 o-1.jpg l-1.jpg

    Doesn’t work in my Ruby model
    `/usr/local/bin/convert -geometry “1024×768>” -strip -quality 90 o-1.jpg l-1.jpg`

    But I found that it will work in other models. So I’m processing the file in one model and the photos in another model. The only problem is that it’s two different processes.

  3. Karl | November 4th, 2007 at 5:26 pm

    odd

Do you have a comment about this jounal entry? Write it here and it will be added to this page. Please remember this is a public forum. Whatever you post here can be viewed by anyone in the world. Please stay on topic.