Forum: Ruby on Rails image conversion w/ 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.
2079c85070a0862b3bb56a8358a33674?d=identicon&s=25 spiceee (Guest)
on 2005-11-16 02:18
(Received via mailing list)
hey

I'm trying to find a way to convert images that were uploaded using
file_column *before* file_column generates a thumb and copies them to
the final dir - this because 50x50 is pretty small and png would be a
much better format (in smaller dimensions) than jpg or gif.

This is what i have in my model (using rmagick for the conversion):

file_column :image, :magick => {:versions => { "thumb" => "50x50" }}
  before_validation :convert_to_png

  def convert_to_png
    if self.image_just_uploaded?
      imgpath = self.image()
      img = ImageList.new(imgpath)
      imgpath = imgpath.sub(/(jpg)$/, 'png')
      img.write(imgpath)
    end
  end

Which manages to save a png version of the original image in the final
dir but the thumb is still being derived from the jpg.

Any clues?

spe.
This topic is locked and can not be replied to.