# Upload image without rmagic

**URL:** <https://www.ruby-forum.com/t/upload-image-without-rmagic/85095>\
**Category:** Rails\
**Created:** [February 10, 2007, 12:06am UTC](https://www.ruby-forum.com/t/upload-image-without-rmagic/85095 "2007-02-10T00:06:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9f8e36/32.png) [@kim](https://www.ruby-forum.com/u/kim)\
**Post date:** [February 10, 2007, 12:06am UTC](https://www.ruby-forum.com/t/upload-image-without-rmagic/85095/1 "2007-02-10T00:06:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9f8e36/32.png) [@kim](https://www.ruby-forum.com/u/kim)\
**Post date:** [February 10, 2007, 1:28am UTC](https://www.ruby-forum.com/t/upload-image-without-rmagic/85095/2 "2007-02-10T01:28:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9f8e36/32.png) [@kim](https://www.ruby-forum.com/u/kim)\
**Post date:** [February 10, 2007, 2:00am UTC](https://www.ruby-forum.com/t/upload-image-without-rmagic/85095/3 "2007-02-10T02:00:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9f8e36/32.png) [@kim](https://www.ruby-forum.com/u/kim)\
**Post date:** [February 10, 2007, 4:57am UTC](https://www.ruby-forum.com/t/upload-image-without-rmagic/85095/4 "2007-02-10T04:57:35Z")

</div>

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

That’s how I do it.

On 2/9/07, Alex W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> easy.  
> path = “#{RAILS\_ROOT}/public/uploads/#{file}”
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

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

---

<div class="post-metadata">

**Author:** ![kim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9f8e36/32.png) [@kim](https://www.ruby-forum.com/u/kim)\
**Post date:** [February 10, 2007, 8:15pm UTC](https://www.ruby-forum.com/t/upload-image-without-rmagic/85095/5 "2007-02-10T20:15:42Z")

</div>

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

On 2/9/07, Alex W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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/](http://www.ruby-forum.com/).
> 
> >

–  
Kim G.  
removed\_email\_address@domain.invalid

“We are all stakeholders in the Karma economy.”

---

<div class="post-metadata">

**Author:** ![kim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9f8e36/32.png) [@kim](https://www.ruby-forum.com/u/kim)\
**Post date:** [February 10, 2007, 8:17pm UTC](https://www.ruby-forum.com/t/upload-image-without-rmagic/85095/6 "2007-02-10T20:17:43Z")

</div>

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

Thanks, -K

On 2/9/07, Carl L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.  
removed\_email\_address@domain.invalid

“We are all stakeholders in the Karma economy.”

---

<div class="post-metadata">

**Author:** ![kim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9f8e36/32.png) [@kim](https://www.ruby-forum.com/u/kim)\
**Post date:** [February 11, 2007, 4:07am UTC](https://www.ruby-forum.com/t/upload-image-without-rmagic/85095/7 "2007-02-11T04:07:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9f8e36/32.png) [@kim](https://www.ruby-forum.com/u/kim)\
**Post date:** [February 10, 2007, 8:22pm UTC](https://www.ruby-forum.com/t/upload-image-without-rmagic/85095/8 "2007-02-10T20:22:43Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > > 
> > > 
> > > end  
> > > end
> 
> “We are all stakeholders in the Karma economy.”
> 
> >

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