Class: Magick::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/CocoaMagick.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width, height, fill = nil) ⇒ Image

Returns a new instance of Image.



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/CocoaMagick.rb', line 241

def initialize(width, height, fill=nil)
  log "Image.initialize #{width} #{height} #{fill}" 
  @width = width
  @height = height
  @image = OSX::NSImage.alloc.initWithSize([width,height])
  @image.lockFocus
  if fill == nil 
    OSX::NSColor.blackColor.set
    OSX::NSRectFill([0,0,width,height])
  elsif fill.class == Magick::GradientFill
    gradient = fill.image
    gradient.drawInRect_fromRect_operation_fraction([0,0,width,height], 
      [0,0,gradient.size.width,gradient.size.height], OSX::NSCompositeCopy, 1.0)
  else
    fill.drawInRect_fromRect_operation_fraction([0,0,width,height], 
      [0,0,fill.size.width,fill.size.height], OSX::NSCompositeCopy, 1.0)
  end
  $width = width
  $height = height
  self
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



240
241
242
# File 'lib/CocoaMagick.rb', line 240

def height
  @height
end

#imageObject

Returns the value of attribute image.



240
241
242
# File 'lib/CocoaMagick.rb', line 240

def image
  @image
end

#widthObject

Returns the value of attribute width.



240
241
242
# File 'lib/CocoaMagick.rb', line 240

def width
  @width
end

Class Method Details

.read(filename) ⇒ Object



268
269
270
271
272
# File 'lib/CocoaMagick.rb', line 268

def self.read(filename)
  log "Image.read #{filename}" 
  image = OSX::NSImage.alloc.initWithContentsOfFile(filename)
  [Image.new(800,600,image)]
end

Instance Method Details

#write(filename) ⇒ Object



262
263
264
265
266
267
# File 'lib/CocoaMagick.rb', line 262

def write(filename)
  log "Image.write #{filename}" 
  @image.unlockFocus
  @image.writePNG(filename)
  self
end