require 'RMagick'

class PhotoController < ApplicationController

[...snip...]

def render_resized_image
@photo=Photo.find(@params["id"])

maxw = @params["width"] != nil ? @params["width"].to_i : 90
maxh = @params["height"] != nil ? @params["height"].to_i : 90
aspectratio = maxw.to_f / maxh.to_f


pic = Magick::Image.from_blob(@photo.image)[0]


picw = pic.columns
pich = pic.rows
picratio = picw.to_f / pich.to_f

if picratio > aspectratio then
scaleratio = maxw.to_f / picw
else
scaleratio = maxh.to_f / pich
end

#breakpoint

thumb = pic.resize(scaleratio)

@response.headers["Content-type"]=@photo.mime
end
end

Requires RMagick


Based on Thumbnailer in Ruby and RMagick


文章来源:http://snippets.dzone.com/posts/show/71

相关文章:

  • 2021-08-17
  • 2021-12-09
  • 2021-09-19
  • 2022-12-23
  • 2021-10-26
  • 2021-10-15
猜你喜欢
  • 2022-12-23
  • 2021-11-25
  • 2021-05-22
  • 2022-01-05
  • 2022-12-23
  • 2021-06-18
  • 2021-04-15
相关资源
相似解决方案