Alex Rivera | Logout

Rails Image Re-sizing on View display?

Asked 2012-05-05T02:05:54.753
19

How do I resize an existing image to, say "260x180?"

I am using Carrierwave and Rmagick currently to upload images to my Amazon S3 storage bucket, and it creates 2 versions of the image: the original, and the thumb version( 70x70).

Now, I know that I can create another version so that three versions would be created, including the 260x180, but I felt like that was over-clogging the storage database, and I was wondering if I could do it on a view level.

I tried

<%= image_tag(@syllabus.image_url, :size => "260x180") %> 

but it seems like it's not working - the images are not identical sizes.

Also, if the image is smaller than my desired output, do I need to do something different than to images that are bigger? For example, do I need to cut the bigger ones, but expand the smaller ones, or will it automatically scale to the desired size?

Edit
Report

1 Answer

6

All Rails does, when seeing your code, is to turn

<%= image_tag(@syllabus.image_url, :size => "260x180") %>

into something like

<image tag="image.jpg" width="260" height="190" ../>

on the page (HTML).

That said, if your code does not look like it's working, try to assign a CSS class to it:

.image-size {
  max-width: 300px;
  max-height: 200px;
}
answered 2012-05-05T02:26:20.060

Your Answer