Ruby on rails: Using Refile Gem, displaying the images without cropping or distorting images -


i'm able upload multiple images, i'm not sure how customize size of image.

this how view images:

<%= attachment_image_tag(image, :file, :fill, 300, 300) %> 

:fill : crops images

300, 300 : height , width

before refile, had hardcoded source of images, , used css fix size of image.

img {   display:block;   max-height: 430px;   max-width: 100%;   width:auto;   height:auto; } 

i wanted have height consistent throughout, width can size , won't distorted or cropped.

at time of post, thinking can away increasing width , height in refile attachment_image_tag option 800, 800, still crops images... also, tried rid of :fill, images won't show, , code breaks.

if take @ refile wiki find there other methods crop image : see here

as can see in css looking max-height of 430px if image height lower 430px not expand 430px think it's not logical use fill, instead use limit

<%= attachment_image_tag(image, :file, :limit, 300, 300) %> 

as documentation says :

limit(img, width, height) :

resize image fit within specified dimensions while retaining original aspect ratio. resize image if larger specified dimensions. resulting image may shorter or narrower specified in either dimension not larger specified values.

in case looking fix height , width size right ? after looking @ code of limit looks :

def limit(img, width, height)   img.resize "#{width}x#{height}>" end 

refile use imagemagick crop image , if not wrong can achieve doing :

x430          # width = size, height = 430 

so think can set width param of limit nil :

<%= attachment_image_tag(image, :file, :limit, nil, 430) %>  

hope help.


Comments