Forum: Ruby on Rails Best way to upload an image and make a thumbnail

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.
093225dffec90d73f5f5685f2db81da0?d=identicon&s=25 Mix Mix (mix)
on 2007-07-11 21:11
Hi, which is the best way to upload an image, keep that and also make a
thumbnail?
The images should not be stored in the database, but as normal image
files in a specific directory.
I think that for the thumbnail i should use rmagick, but for the upload
? (something which work with and without javascript, in every browser)
Thanks :)
54077fb03c95861af85880218cf7aef2?d=identicon&s=25 Gokhan Arli (sylow)
on 2007-07-11 21:19
Try fleximage

http://fleximage.rubyforge.org/


Gokhan
www.sylow.net

Mix Mix wrote:
> Hi, which is the best way to upload an image, keep that and also make a
> thumbnail?
> The images should not be stored in the database, but as normal image
> files in a specific directory.
> I think that for the thumbnail i should use rmagick, but for the upload
> ? (something which work with and without javascript, in every browser)
> Thanks :)
3bc555eb01bf510bf098c07b7db543cc?d=identicon&s=25 CPerry (Guest)
on 2007-07-11 21:20
(Received via mailing list)
Just curious, is there any special reason as to why you would not want
them stored in the database? How will you be referencing back to the
images later?

I know this not helping you original question, but I was just curious
to know why you would not want them stored.

--Cory
093225dffec90d73f5f5685f2db81da0?d=identicon&s=25 Mix Mix (mix)
on 2007-07-11 21:31
CPerry wrote:
> Just curious, is there any special reason as to why you would not want
> them stored in the database? How will you be referencing back to the
> images later?
>
> I know this not helping you original question, but I was just curious
> to know why you would not want them stored.
>
> --Cory

Actually would not be a problem, but with a lot of images all with a
thumbnail i think that the db dimension would grow exponentially and
maybe decrease the performance, and also because with just images i can
move them to another server and reference to it, without move all the db
To reference them i think it's important to save just the name and then
load it in the view as a normal image, could be a possible solution? :)


> Try fleximage
>
> http://fleximage.rubyforge.org/

I think it could be quite heavy to resize on the fly images, especially
when there are pages with 40 images, ok the cache, but isn't better to
resize them just one time and then use the thumb or the original when
they are needed ?
0900e6a4828bd989f96427082c6c74ca?d=identicon&s=25 Mike Garey (random52k)
on 2007-07-11 21:42
(Received via mailing list)
I use attachment_fu with RMagick for this.  It also supports
lightweight image processors such as ImageScience.  You can find a
howto here:

http://clarkware.com/cgi/blosxom/2007/02/24

Mike
Ab0b702e7fcc79bb7d2c6c67f64e1b4d?d=identicon&s=25 tmac (Guest)
on 2007-07-11 21:56
(Received via mailing list)
I'd do a system call to image magic's convert program to make the
thumbnail... about the best performance your going to get

def thumbnail(temp, target)
  system(
    "/usr/local/bin/convert #{escape(temp)} -resize 48x48!
#{escape(target)}"
  )
end

DHH touches on this in "Outsourcing the performance-intensive
functions" on this blog page:
http://www.loudthinking.com/arc/2006_09.html

Not really following you on what your asking about with the how to
upload part of the question? and not sure what javascript has to do
with it?  It should just be a file-upload field as far as the browser
goes.  For saving on the server I do something like this in one of my
models:

  def save_file(file_name, file)
    fh = File.open(file_name, 'w')
    fh.write(file.read)
    fh.close
  end

  def image=(img)
    return if img.blank?
    save_file("/whatever/name/for_my_file.jpg", img)
  end

good luck!
Tim
093225dffec90d73f5f5685f2db81da0?d=identicon&s=25 Mix Mix (mix)
on 2007-07-15 09:26
Mike Garey wrote:
> I use attachment_fu with RMagick for this.  It also supports
> lightweight image processors such as ImageScience.  You can find a
> howto here:
>
> http://clarkware.com/cgi/blosxom/2007/02/24
>
> Mike

does rmagick take a lot of memory to make thumbnails? i don't know if
choose it or imagescience (that i think could be ok, because i've just
to resize)
54077fb03c95861af85880218cf7aef2?d=identicon&s=25 Gokhan Arli (sylow)
on 2007-07-15 12:59
I do resizing when they are hit first time and cache them.

Gokhan
www.sylow.net
Mix Mix wrote:

>
>> Try fleximage
>>
>> http://fleximage.rubyforge.org/
>
> I think it could be quite heavy to resize on the fly images, especially
> when there are pages with 40 images, ok the cache, but isn't better to
> resize them just one time and then use the thumb or the original when
> they are needed ?
This topic is locked and can not be replied to.