Class: Pixelflut::Image
- Inherits:
-
Object
- Object
- Pixelflut::Image
- Defined in:
- lib/pixelflut/image.rb
Instance Method Summary collapse
- #each_pixel ⇒ Object
- #height ⇒ Object
-
#initialize(file_name) ⇒ Image
constructor
A new instance of Image.
- #resize_to(width, height = nil) ⇒ Object
- #scale(factor) ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(file_name) ⇒ Image
Returns a new instance of Image.
7 8 9 10 11 |
# File 'lib/pixelflut/image.rb', line 7 def initialize(file_name) @image = Magick::ImageList.new(file_name).first rescue Magick::ImageMagickError => e raise(LoadError, e., cause: e) end |
Instance Method Details
#each_pixel ⇒ Object
29 30 31 32 |
# File 'lib/pixelflut/image.rb', line 29 def each_pixel return to_enum(__method__) unless block_given? @image.each_pixel { |px, x, y| 0 != px.alpha and yield(x, y, px) } end |
#height ⇒ Object
17 18 19 |
# File 'lib/pixelflut/image.rb', line 17 def height @image.rows end |
#resize_to(width, height = nil) ⇒ Object
21 22 23 |
# File 'lib/pixelflut/image.rb', line 21 def resize_to(width, height = nil) @image.resize_to_fit!(width, height) end |
#scale(factor) ⇒ Object
25 26 27 |
# File 'lib/pixelflut/image.rb', line 25 def scale(factor) @image.scale!(factor) end |
#width ⇒ Object
13 14 15 |
# File 'lib/pixelflut/image.rb', line 13 def width @image.columns end |