[导入]Thumbnailer in Ruby and RMagick

后端开发   发布日期:2025年07月22日   浏览次数:179
require 'RMagick'

maxwidth = 120
maxheight = 160
aspectratio = maxwidth.to_f / maxheight.to_f
imgfile = 'world'

pic = Magick::Image.read(imgfile + '.jpg').first
imgwidth = pic.columns
imgheight = pic.rows
imgratio = imgwidth.to_f / imgheight.to_f
imgratio > aspectratio ? scaleratio = maxwidth.to_f / imgwidth : scaleratio = maxheight.to_f / imgheight
thumb = pic.resize(scaleratio)

white_bg = Magick::Image.new(maxwidth, thumb.height)
pic = white_bg.composite(thumb, Magick::CenterGravity, Magick::OverCompositeOp)
pic.write(imgfile + '.thumb.jpg')

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

以上就是[导入]Thumbnailer in Ruby and RMagick的详细内容,更多关于[导入]Thumbnailer in Ruby and RMagick的资料请关注九品源码其它相关文章!