allow :style => Proc
Reported by linoj | May 15th, 2008 @ 11:40 PM
Requesting the following one-line patch be added:
in paperclip/attachment.rb#post_process, after the line
dimensions, format = args
add
dimensions = dimensions.call(instance) if dimensions.respond_to? :call
example usage:
suppose your model has columns for custom_width, custom_height
:styles => { :small => "50x50>",
:custom => Proc.new {|instance| "#{instance.custom_width}x#{instance.custom_height}>" }
also, to allow updating the thumbs when width,height change, I used acts_as_modified plugin in the model:
acts_as_modified
def before_save
image.reprocess! if custom_width_modified? || custom_height_modified?
end
Comments and changes to this ticket
-

Tim Haines June 13th, 2008 @ 10:57 AM
I'd like the ability to do something similar to this. Not quite sure what I want - but it does involve having custom widths and heights.. this would probably solve it for me.
-

Tim Haines May 22nd, 2008 @ 10:31 PM
Okay. Have thought it through a bit more. What I'd like to do is specify a thumb width and height in the image url called from a view. When that url is hit, ideally Paperclip would load the thumbnail from storage if that dimension pair had been requested previously, or create the thumbnail on the fly if the dimension pair hadn't been requested previously..
I think the request by linoj will work for me though - it'll just require a bit more hoop jumping.
-
Jon Yurek May 27th, 2008 @ 02:27 PM
- → State changed from new to resolved
I put this into master the other day. Thanks for the suggestion.
Tim, I don't think that's necessarily something that would be useful to people-at-large, so I probably won't put it in. You can definitely hack something in, though, with a combination of using the Procs and overriding Paperclip::Attachment#url.
-
Jon Yurek June 13th, 2008 @ 11:00 AM
- no changes were found...
-

David Baldwin September 16th, 2008 @ 12:24 AM
- → Tag cleared.
Note that you can call this reprocess! in a before_save operation without acts_as_modified in Rails 2.1. You can use the dirty object functionality like this:
def before_save logo.reprocess! if logo_width_changed? || logo_height_changed? end
Here is additional information on dirty objects from Ryan Daigle's blog... http://ryandaigle.com/articles/2...
-

David Baldwin September 16th, 2008 @ 12:29 AM
Sorry, didn't realize you could use Markdown...
Note that you can call this reprocess! in a before_save operation without acts_as_modified in Rails 2.1. You can use the dirty object functionality like this:
def before_save logo.reprocess! if logo_width_changed? || logo_height_changed? endHere is additional information on dirty objects from Ryan Daigle's blog...
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
