# Resizing images in rails?

**URL:** <https://rubytalk.org/t/resizing-images-in-rails/48657>\
**Category:** ruby-talk\
**Created:** [27 August 2008 13:51 UTC](https://rubytalk.org/t/resizing-images-in-rails/48657 "2008-08-27T13:51:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ravi\_Katta](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@Ravi\_Katta](https://rubytalk.org/u/Ravi_Katta)\
**Post date:** [27 August 2008 13:51 UTC](https://rubytalk.org/t/resizing-images-in-rails/48657/1 "2008-08-27T13:51:32Z")

</div>

Hi,

&nbsp;&nbsp;&nbsp;&nbsp;how to resize the images in rails app?  
&nbsp;&nbsp;&nbsp;&nbsp;i want 400X300 size images to display in my app.But if user enter  
600X800 how to resize the image without effect on clarity?

&nbsp;&nbsp;now i am using this code

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image =  
Magick::Image.read("#{RAILS\_ROOT}/public/gallery/#{review\_img}").first  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;selected\_image = image.crop\_resized(400,400)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;selected\_image.write("#{RAILS\_ROOT}/public/gallery/#{review\_img}")

&nbsp;&nbsp;&nbsp;But it extract height and width.i dont want to extract only resize  
the image.  
&nbsp;&nbsp;&nbsp;any suggestion are appreciated.

thanks,  
ravi.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Tim\_Hunter1](https://avatars.discourse-cdn.com/v4/letter/t/3ec8ea/32.png) [@Tim\_Hunter1](https://rubytalk.org/u/Tim_Hunter1)\
**Post date:** [27 August 2008 14:27 UTC](https://rubytalk.org/t/resizing-images-in-rails/48657/2 "2008-08-27T14:27:14Z")

</div>

Ravi Katta wrote:

> &nbsp;&nbsp;&nbsp;Hi,
> 
> &nbsp;&nbsp;&nbsp;&nbsp;how to resize the images in rails app?  
> &nbsp;&nbsp;&nbsp;&nbsp;i want 400X300 size images to display in my app.But if user enter  
> 600X800 how to resize the image without effect on clarity?
> 
> &nbsp;&nbsp;now i am using this code
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image =  
> Magick::Image.read("#{RAILS\_ROOT}/public/gallery/#{review\_img}").first  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;selected\_image = image.crop\_resized(400,400)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;selected\_image.write("#{RAILS\_ROOT}/public/gallery/#{review\_img}")
> 
> &nbsp;&nbsp;&nbsp;But it extract height and width.i dont want to extract only resize  
> the image.  
> &nbsp;&nbsp;&nbsp;any suggestion are appreciated.
> 
> thanks,  
> ravi.

Here's a description of RMagick's resizing methods:  
[http://studio.imagemagick.org/RMagick/doc/comtasks.html#thumb\](http://studio.imagemagick.org/RMagick/doc/comtasks.html#thumb%5C). Also see  
the section "Resizing to a maximum (or minimum) size".

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Michael\_Morin](https://avatars.discourse-cdn.com/v4/letter/m/d78d45/32.png) [@Michael\_Morin](https://rubytalk.org/u/Michael_Morin)\
**Post date:** [28 August 2008 15:51 UTC](https://rubytalk.org/t/resizing-images-in-rails/48657/3 "2008-08-28T15:51:13Z")

</div>

Ravi Katta wrote:

> &nbsp;&nbsp;&nbsp;Hi,
> 
> &nbsp;&nbsp;&nbsp;&nbsp;how to resize the images in rails app?  
> &nbsp;&nbsp;&nbsp;&nbsp;i want 400X300 size images to display in my app.But if user enter  
> 600X800 how to resize the image without effect on clarity?
> 
> &nbsp;&nbsp;now i am using this code
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image =  
> Magick::Image.read("#{RAILS\_ROOT}/public/gallery/#{review\_img}").first  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;selected\_image = image.crop\_resized(400,400)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;selected\_image.write("#{RAILS\_ROOT}/public/gallery/#{review\_img}")
> 
> &nbsp;&nbsp;&nbsp;But it extract height and width.i dont want to extract only resize  
> the image.  
> &nbsp;&nbsp;&nbsp;any suggestion are appreciated.
> 
> thanks,  
> ravi.

First, resizing 400x300 to 600x800 changes the aspect ratio. The image will appear "squashed." Second, scaling up will always involve some pixelization, blurriness or other unwanted things. Third, you can have the web browser do this for you. See the width and height attributes to the img tag.

> **···**
>
> --  
> Michael Morin  
> Guide to Ruby
> 
> > **[Ruby Programming](https://www.thoughtco.com/ruby-programming-4133469)**
> >
> > Learn the Ruby programming language with simple, step-by-step tutorials.
> 
> Become an About.com Guide: beaguide.about.com  
> About.com is part of the New York Times Company
