00 - introduction

来自「O Reilly Ruby Cookbook source code」· 代码 · 共 43 行

TXT
43
字号
require 'rubygems'require 'RMagick'img = Magick::Image.read('myimage.jpg').firstwidth, height = 100, 100thumb = img.resize(width, height)thumb.write('mythumbnail.jpg')#---scale_factor = 0.15thumb = img.resize(scale_factor)thumb.write("mythumbnail.jpg")#---def thumb_no_bigger_than(img, width, height)  img.change_geometry("#{width}x#{height}") do |cols, rows, img|    img.resize(cols, rows)  endendimg.rows                                        # => 470img.columns                                     # => 892thumb = thumb_no_bigger_than(img, 100, 100)thumb.rows                                      # => 53thumb.columns                                   # => 100#---thumb = img.scale(width, height)thumb = img.scale(scale_factor)thumb = img.sample(width, height)thumb = img.sample(scale_factor)thumb = img.thumbnail(width, height)thumb = img.thumbnail(scale_factor)#---thumb = img.crop(Magick::CenterGravity, 80, 100)#---# With an x, y offset relative to the upper-left corner:thumb = img.crop(x, y, width, height)# With a GravityType and the x, y offset:thumb = img.crop(Magick::WestGravity, x, y, width, height)# With a GravityType:thumb = img.crop(Magick::EastGravity, width, height)#---

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?