Ruby/GDを使って画像の拡大縮小
ふと、Rubyを使って画像のサムネイルを出力したいなと思い立ち、Ruby/GDの調査。
必要そうなメソッドのみを抜き出してみた。
のだが!
画像をいじるのはRMagickを使った方が楽っぽいことが発覚orz
RMagickのHTMLヘルプなんかも発見。
GD::Image.new(width, height)
creates a new palette image instance with specified width and height.
GD::Image.newFromJpeg(file)
Creates a new image instance from JPEG file. file is a File object.
GD::Image.new_from_jpeg(filename)
creates a new Jpeg image instance from filename. filename is a String object which specifies the location of the image file.
GD::Image#destroy
Free the memory associated with the image instance.
GD::Image#copy(dest_img, dest_X, dest_Y, self_X, self_Y, width, height)
Copy a portion of the image at (self_X, self_Y) with specified width and height to (dest_X, dest_Y) of dest_img.
GD::Image#copyResized(dest_img, dst_X, dst_Y, self_X, self_Y, dest_width, dest_height, self_width, self_height)
Copy a portion of the image at (self_X, self_Y) with specified self_width and self_height to dest_img at (dest_X, dest_Y) with specified dest_width and dest_height.
てか、このメソッドの説明、オリジナルのmanualだと間違ってる気がするのだが…。
GD::Image#jpeg(file, quality)
(gd-1.8 or later)
Outputs the image to the specified file with quality in Jpeg format. If quality is set to nagative, the default IJG JPEG quality value (which should yield a good general quality size trade-off for most situations) is used. For practical purposes, quality should be a value in the range 0-95.