Forum: Ruby on Rails More flexible file column?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
DJ Tequila (Guest)
on 2006-06-01 19:45
(Received via mailing list)
The file column plug-in is great, but there is a problem with it. Well,
two... But the other is well documented now. :^)

Consider a time when you've created a CMS for a client and it's been in
use for over a year. Say 1500+ images have been uploaded so far. Now the
client comes back with a simple request... 'Can you change the thumbnail
size to 80/90, rather than 70/70? It shouldn't take you more than half a
day...'
'No problem!' you say, 'I'll just change the CSS *here*, and the article
model *here* and... Oh.' Broken images all over the place. No images at
all if you use Firefox.

It wasn't quite 1500 images, but I ended up writing a script to
systematically go through each image in the database and resize it  to
order... File column helpfully handles removing the old sizes for you.

This is all a but un-rails-like though. I'd expect the plugin to
automatically realise that the resized image is missing and create it on
the fly. It has all the tools and data to do so, and the perfomance hit
will only be felt once, by the first user who encounters the image. I'd
take that to be an acceptable compromise.

I have, in fact, written such code quite successfully in PHP. However,
I'm new to Ruby and not completely comfortable with it yet. Has anyone
done it themselves? If not, has anyone looked into the File Column code
enough to give me a few pointers? Obviously if I get it working I'll
release it back to the Rails community...

Or does anyone think I've gone mad and should stick to scripts? ;^)
Steven H. (Guest)
on 2006-06-01 20:08
(Received via mailing list)
I thought file column made this sort of thing really easy.

|file_column :image, :magick => { :geometry => "800x600>" }

see: http://wiki.rubyonrails.org/rails/pages/HowToUseFileColumn
|
Robert W. (Guest)
on 2006-06-01 20:33
(Received via mailing list)
2006/6/1, DJ Tequila <removed_email_address@domain.invalid>:
> I have, in fact, written such code quite successfully in PHP. However,
> I'm new to Ruby and not completely comfortable with it yet. Has anyone
> done it themselves? If not, has anyone looked into the File Column code
> enough to give me a few pointers? Obviously if I get it working I'll
> release it back to the Rails community...
>
> Or does anyone think I've gone mad and should stick to scripts? ;^)
>

this is how i did it (all images were jpgs):

lib/image_resize.rb:

require "action_controller/test_process"

Image.find_all.each do |i|
 i.path=ActionController::TestUploadedFile.new(i.path, "image/jpeg")
 i.save
end

start:

script/runner "load('image_resize.rb')"

--robert
Jason P. (Guest)
on 2006-06-01 20:44
> This is all a but un-rails-like though. I'd expect the plugin to
> automatically realise that the resized image is missing and create it on
> the fly. It has all the tools and data to do so, and the perfomance hit
> will only be felt once, by the first user who encounters the image. I'd
> take that to be an acceptable compromise.

I'm building something with file_column right now and I think this is a
great idea.  I have to admit at first I thought you were just asking for
more features.  I listened to Sebastian speak at Canada on Rails and
everyone was asking him 'can you make it do this? How about this? What
about this?'

The Rails rationale was to do what was right for most of the people most
of the time, and I think this fits. Unfortunately I have not the
technical know-how to help out with it yet, but let me know how it goes.
Raja Bhatia (Guest)
on 2006-06-01 20:55
(Received via mailing list)
1) modify the model to support a new thumbnail size

2)

Attachment.find(:all).each do |a|
    a.asset = File.open(a.asset) #opens each file_column based asset
    a.save #rebuilds and saves - huzzah
end

from our friends at caboose - reference :
http://blog.caboo.se/articles/2006/01/09/file_colu...

-raja

Raja Bhatia, FiveLimes, Inc.
http//fivelimes.com
Kyle M. (Guest)
on 2006-06-01 21:28
(Received via mailing list)
On 6/1/06, DJ Tequila <removed_email_address@domain.invalid> wrote:
> all if you use Firefox.
This is why image transformations should be made in the view, not in
the model.  the model should hold the canonical image, and the view
should create derivative images.>

> I have, in fact, written such code quite successfully in PHP. However,
> I'm new to Ruby and not completely comfortable with it yet. Has anyone
> done it themselves? If not, has anyone looked into the File Column code
> enough to give me a few pointers? Obviously if I get it working I'll
> release it back to the Rails community...

Check out my branch at http://svn.kylemaxwell.com/file_column/.  It
implements view-side image transformations.  You'll have to look
through the source, particualarly magick_file_column.rb, since I
haven't kept up the docs.

I'm open to the idea of forking file_column, as I am actively
developing my branch.  I used to work closely with Sebastian on
file_column development.  This appears stalled, as a point release
hasn't happened in several months.

--
Kyle M.
Chief Technologist
E Factor Media // FN Interactive
removed_email_address@domain.invalid
1-866-263-3261
Rick O. (Guest)
on 2006-06-02 09:13
(Received via mailing list)
> It wasn't quite 1500 images, but I ended up writing a script to
> systematically go through each image in the database and resize it  to
> order... File column helpfully handles removing the old sizes for you.

Acts as attachment supports multiple thumbnails for a single image.  I
usually store the original image plus any smaller versions I may need.
 I've changed thumbnail sizes several times during the development of
my current client project.  I just loop through all uploaded images
and re-process everything in script/console.

If you're doing this kind of thing often, maybe you need a different
solution?

http://www.infoq.com/articles/Agile-Asset-Management
This topic is locked and can not be replied to.