Best way to upload an image and make a thumbnail


#1

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 :slight_smile:


#2

Try fleximage

http://fleximage.rubyforge.org/

Gokhan
www.sylow.net

Mix M. 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 :slight_smile:


#3

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


#4

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? :slight_smile:

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 ?


#5

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


#6

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


#7

Mike G. 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)


#8

I do resizing when they are hit first time and cache them.

Gokhan
www.sylow.net
Mix M. 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 ?