# Variable sizes with paperclip

**URL:** <https://www.ruby-forum.com/t/variable-sizes-with-paperclip/176942>\
**Category:** Rails\
**Created:** [October 8, 2009, 5:39pm UTC](https://www.ruby-forum.com/t/variable-sizes-with-paperclip/176942 "2009-10-08T17:39:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gorter9](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/839c29/32.png) [@gorter9](https://www.ruby-forum.com/u/gorter9)\
**Post date:** [October 8, 2009, 5:39pm UTC](https://www.ruby-forum.com/t/variable-sizes-with-paperclip/176942/1 "2009-10-08T17:39:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gorter9](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/839c29/32.png) [@gorter9](https://www.ruby-forum.com/u/gorter9)\
**Post date:** [October 8, 2009, 7:34pm UTC](https://www.ruby-forum.com/t/variable-sizes-with-paperclip/176942/2 "2009-10-08T19:34:25Z")

</div>

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  
([GitHub - delynn/userstamp: This Rails plugin extends ActiveRecord::Base to add automatic updating of created\_by and updated\_by attributes of your models in much the same way that the ActiveRecord::Timestamp module updates created\_(at/on) and updated\_(at/on) attributes.](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

---

<div class="post-metadata">

**Author:** ![gorter9](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/839c29/32.png) [@gorter9](https://www.ruby-forum.com/u/gorter9)\
**Post date:** [October 9, 2009, 2:40pm UTC](https://www.ruby-forum.com/t/variable-sizes-with-paperclip/176942/3 "2009-10-09T14:40:55Z")

</div>

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
