regenerate paperclip thumbnails

Paperclip is a cool new alternative to attachment_fu for uploading files in Rails.

(There’s a good tutorial on Jim Neath’s blog)

The only gotcha I’ve run into so far is regenerating thumbnails. With attachment_fu, you just re-save your models. For Paperclip, there is a rake task.

rake paperclip:refresh CLASS=YourModelName

Hopefully that saves someone ten minutes of Googling :)


what other people thought

Hey Nik,

I’ve been using Paperclip quite a bit. You can regen thumbs by calling .reprocess! On some classes I’m setting up custom widths and heights and then reprocessing the thumbs when the model is saved..

There’s some other nice stuff that isn’t well documented yet, such as setting the thumb width and height via proc, and saving the geometry as an additional column.

Not that it will effect you guys – but there’s a few gotch’yas on windows too. The plugin doesn’t work very nicely with tempfiles on Windows. You need to set binmode when you open the files, and pull a couple of other tricks..

Pretty sweet plugin though – I like it for it’s simplicity. We’ve been feeding it with swfupload.

Tim.

Tim Haines, July 5th, 2008 at 7:54 pm

@tim: Aah, thanks for that! .reprocess! is actually what I was looking for :)

Nik, July 6th, 2008 at 2:07 pm

Is there a way to change dpi setting for jpegs?
Or compression quality for that matter?

Dios, July 10th, 2008 at 3:27 pm

@Dios: All it does is use ImageMagick on the command line, so it should be easy enough to make changes so that it passes the correct arguments through to “convert”. (check lib/paperclip/thumbnail.rb)

Nik, July 10th, 2008 at 3:36 pm

Hi!

I discovered Paperclip one week ago and I’m already in love with it!

Does someone knows if it’s possible to link a file to a paperclip-enabled model from the server’s filesystem (not using a user file field input). If yes, how?
I don’t know if I’ve to use File, TempFile or …

Thanks!

aurels, July 29th, 2008 at 7:23 pm

I found my way simply using File:

my_model.file = File.new(“/path/to/file.pdf”)
my_model.save

;-)

aurels, July 29th, 2008 at 8:11 pm

I have been trying to use Paperclip with Windows, but keep getting an error that says “has_attached_file” is an undefined method. Any idea what is going wrong, or whether I’m missing something here?

Dan, July 30th, 2008 at 1:48 am

@Dan: I’m not sure, we’re all on OS X here.

Although, it does sound suspiciously like you might have forgotten to restart your server…. (to load the plugin)

Nik, July 30th, 2008 at 10:10 am

[...] Sería interesante mirarlo más en profundidad para que sí lo haga en caso de que le estemos pasando un nuevo fichero de imagen, pero por el momento me vale para mis propósitos… y de todos modos quizá es hora de irse cambiando a paperclip, que por lo que tengo entendido, no tiene este comportamiento… aunque tampoco es del todo cómodo porque he leído que para regenerar los thumbnails en paperclip es necesario lanzar una tarea rake. [...]

Cómo evitar la regeneración de thumbnails con attachment_fu — Jaime Iniesta - Programador web freelance Ruby on Rails, August 20th, 2008 at 9:15 pm

Hi, you mention .reprocess! on the above comments.
How would I use .reprocess! on my application? Is it used on a rake task?
Also, how can we save the Geometry into the database? Can you point me to a tutorial on how to do that?
Thanks a lot!

Ethan, July 24th, 2009 at 12:56 pm

Thanks It really save me precious time!

Andre Durao, November 28th, 2009 at 2:14 am

have your say