Controlling image processing in Spree

139 views
Skip to first unread message

Randy Terbush

unread,
Mar 27, 2013, 12:52:44 PM3/27/13
to spree...@googlegroups.com
I have managed to control some of the ImageMagick/Paperclip processing of images by creating the following decorator.

Spree::Image.class_eval do
 attachment_definitions
[:attachment][:convert_options] = {
 
'mini' => "-strip -auto-orient -gravity center -extent 48x48",
 
'small' => "-strip -auto-orient -gravity center -extent 100x100",
 
'product' => "-strip -auto-orient -gravity center -extent 250x250",
 
'large' => "-strip -auto-orient -gravity center -extent 600x600"
 
}
end


However, I am discovering that the order of parameters passed to convert is important ans specifically, if I want to -trim the images, I need to do that before the -resize flag. I am not clear where I can control that entire set of parameters passed to convert since the -resize paperclip_style flag is passed in first.

Any suggestions on how to control the entire set of parameters?

Appreciate the help.

Randy Terbush

unread,
Mar 27, 2013, 6:54:36 PM3/27/13
to spree...@googlegroups.com
Developing a bad habit of talking to myself in here... :-)

I've worked out a hacky solution thanks to some input from @jotto. You can see what I came up with here.

Nate Lowrie

unread,
Mar 28, 2013, 9:44:38 AM3/28/13
to spree...@googlegroups.com
Randy,

The arguments are just standard ImageMagik arguments. So, you can look at their documents to figure out what flags you need in the correct order. Also, a quick way to test your parameters is to use convert a sample image from the command line using ImageMagick. It's a much quicker way to work out the details compared to editing the decorator and uploading through the admin interface again.

Regards,

Nate

Randy Terbush

unread,
Mar 28, 2013, 9:58:57 AM3/28/13
to spree...@googlegroups.com
It is actually more difficult than that Nate. I'm progressing. :-)

The problem is the order of the arguments that Paperclip constructs.

In standard Paperclip, if I add the flags that I need in the decorator to add additional flags for each style, all of the :convert_options will be added AFTER, the -resize operation in Paperclip. So for example, if you want to change the filter that the -resize operation uses, passing a -filter flag after the -resize flag will have no effect. Biggest discovery here was that the order of flags passed to convert is important.

If you want to -trim whitespace from the image, adding a -trim after the -resize will not produce the results you are after.

So the change in the gist allows you to add the :convert options before the -resize flag and the hack is that I added a few enhancement and extent flags after the resize operation.

What would be nice to do is to create :before_ops and :after_ops settings for the :attachment definitions, but that change eluded me.



--
Randy


--
You received this message because you are subscribed to a topic in the Google Groups "Spree" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/spree-user/L5bgZEtZTVs/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to spree-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Nate Lowrie

unread,
Mar 28, 2013, 10:52:42 AM3/28/13
to spree...@googlegroups.com
Ah, I see now. Glad you are working things out.

+1 from me for the before and after resize options preferences.

Regards,

Nate
Reply all
Reply to author
Forward
0 new messages