# Resizing images in rails?

**URL:** <https://www.ruby-forum.com/t/resizing-images-in-rails/147012>\
**Category:** Ruby\
**Created:** [August 27, 2008, 3:56pm UTC](https://www.ruby-forum.com/t/resizing-images-in-rails/147012 "2008-08-27T15:56:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ravikanth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ce7236/32.png) [@ravikanth](https://www.ruby-forum.com/u/ravikanth)\
**Post date:** [August 27, 2008, 3:56pm UTC](https://www.ruby-forum.com/t/resizing-images-in-rails/147012/1 "2008-08-27T15:56:06Z")

</div>

Hi,

```
how to resize the images in rails app?
i want 400X300 size images to display in my app.But if user enter

```

600X800 how to resize the image without effect on clarity?

now i am using this code

```
 image =

```

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

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

thanks,  
ravi.

---

<div class="post-metadata">

**Author:** ![ravikanth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ce7236/32.png) [@ravikanth](https://www.ruby-forum.com/u/ravikanth)\
**Post date:** [August 27, 2008, 4:31pm UTC](https://www.ruby-forum.com/t/resizing-images-in-rails/147012/2 "2008-08-27T16:31:48Z")

</div>

Ravi K. wrote:

> Hi,
> 
> ```
> how to resize the images in rails app?
> i want 400X300 size images to display in my app.But if user enter
> 
> ```
> 
> 600X800 how to resize the image without effect on clarity?
> 
> now i am using this code
> 
> ```
> image =
> 
> ```
> 
> Magick::Image.read(“#{RAILS\_ROOT}/public/gallery/#{review\_img}”).first  
> selected\_image = image.crop\_resized(400,400)  
> selected\_image.write(“#{RAILS\_ROOT}/public/gallery/#{review\_img}”)
> 
> But it extract height and width.i dont want to extract only resize  
> the image.  
> 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). Also see  
the section “Resizing to a maximum (or minimum) size”.

---

<div class="post-metadata">

**Author:** ![ravikanth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ce7236/32.png) [@ravikanth](https://www.ruby-forum.com/u/ravikanth)\
**Post date:** [August 28, 2008, 5:56pm UTC](https://www.ruby-forum.com/t/resizing-images-in-rails/147012/3 "2008-08-28T17:56:18Z")

</div>

Ravi K. wrote:

> Magick::Image.read("#{RAILS\_ROOT}/public/gallery/#{review\_img}").first  
> selected\_image = image.crop\_resized(400,400)  
> selected\_image.write("#{RAILS\_ROOT}/public/gallery/#{review\_img}")
> 
> But it extract height and width.i dont want to extract only resize  
> the image.  
> 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.
