Upload image without rmagic

I need a way to upload an image and display it without using any of
the plugins that use rmagic. I have used the plugins (file_column,
fleximage) which both use rmagic and gave me problems (never got
fleximage to work)

Thanks in advance - K

I got FlexImage to work! Yahoo. I am still looking for a way to upload
images without rmagic though. Any suggestions?

Kim wrote:

I need a way to upload an image and display it without using any of
the plugins that use rmagic. I have used the plugins (file_column,
fleximage) which both use rmagic and gave me problems (never got
fleximage to work)

Thanks in advance - K

To simply write an uploaded file to the disk on the server is pretty
easy.

view

<% form_tag({:action => ‘upload’}, :multipart => true) do %>
<%= file_field_tag ‘file’ %>
<%= submit_tag ‘Upload!’ %>
<% end %>

controller

def upload
file = params[:file].original_filename
path = “#{RAILS_ROOT}/public/uploads/#{file}”
File.open path, ‘wb’ do |f|
f.write(params[:file].read)
end

flash[:notice] = "#{file} uploaded successfuly to #{path}"
redirect_to :action => 'index'

end

If you want to manipulate the images in any way you must use RMagick.
As far as I know it’s the only way to resize images in ruby.

Although, if you don;t want to use RMagick, you can use ImageMagick via
command line. I haven’t done this exactly, but ImageMagick gives you a
command line program called “convert”.

def resize_image(file, size)
`convert #{file} --resize #{size}" #maybe
end

Now I don’t know the exact format of the arguments to convert but
something like that may work.

You can resizes images using /usr/local/bin/convert #{whatever}.

That’s how I do it.

On 2/9/07, Alex W. [email protected] wrote:

easy.
path = “#{RAILS_ROOT}/public/uploads/#{file}”


Posted via http://www.ruby-forum.com/.


EPA Rating: 3000 Lines of Code / Gallon (of coffee)

How about if I want to load an image to a DB?

On 2/9/07, Alex W. [email protected] wrote:

To simply write an uploaded file to the disk on the server is pretty
file = params[:file].original_filename
As far as I know it’s the only way to resize images in ruby.
something like that may work.


Posted via http://www.ruby-forum.com/.


Kim G.
[email protected]

“We are all stakeholders in the Karma economy.”

Are you using ImageMagic? Can you explain: /usr/local/bin/convert #{whatever}.

Thanks, -K

On 2/9/07, Carl L. [email protected] wrote:

the plugins that use rmagic. I have used the plugins (file_column,
<%= file_field_tag ‘file’ %>


EPA Rating: 3000 Lines of Code / Gallon (of coffee)


Kim G.
[email protected]

“We are all stakeholders in the Karma economy.”

Carl L. wrote:

As for loading an image to a DB, I really would advise against doing
that. Having all that binary data in the database would slow it down a
lot. There are a lot of alternatives and unless your site grows
massive, you won’t need anything more than just writing the files in a
directory somewhere.

With proper caching and optimizations, it doesn;t affect performance
much, and it makes backing it all up much easier.

Yeah, that’s using imagemagick, however it’s not loading the image
into the main mongrel process and making memory usage shoot through
the roof. It’s using the command line tool (convert). Basically, write
the image to be processed to a file somewhere and run convert on it.

As for loading an image to a DB, I really would advise against doing
that. Having all that binary data in the database would slow it down a
lot. There are a lot of alternatives and unless your site grows
massive, you won’t need anything more than just writing the files in a
directory somewhere.

On 2/10/07, Kim G. [email protected] wrote:

end
end

“We are all stakeholders in the Karma economy.”


EPA Rating: 3000 Lines of Code / Gallon (of coffee)