Variable sizes with paperclip

How can i create variable sizes with paperclip.

That the user can set the size he want and paperclip makes the picture.
I only can create fixed sizes.

On 08 Oct 2009, at 17:39, GG9 Rails wrote:

How can i create variable sizes with paperclip.

That the user can set the size he want and paperclip makes the
picture.
I only can create fixed sizes.

Probably adding the following to your model will work:

before_post_process :get_thumbnail_sizes

def get_thumbnail_sizes
   User.stamper.thumbnail_sizes.each do |target_size|
      asset.styles[target_size.name] = { :geometry =>

target_size.geometry, :format => “png”, :processors => “thumbnail” }
end
end

User.stamper is something you can get by adding the Userstamp plugin
(http://github.com/delynn/userstamp
) to your project (to make it easy on yourself). There’s still a
couple of things you’ll need to figure out yourself, but this should
at least get you started.

Best regards

Peter De Berdt

I found a more simple solotion now

def self.last_avatar
Avatar.find(:last)
end

def self.new_avatar_size
last_avatar.avatar_size
rescue
“48x48”
end

has_attached_file :avatar, :styles => { :small => new_avatar_size,
:large => “500x500>” },

The only problem left now is

When two users doo create an avatar on same time the and one of them is
faster he got’s the size of last user

I can’t use conditions into the model

request.remote_ip doesn’t work in model, also cookies is not usable for
find the richt id