class GD::TrueColorImage

Private Class Methods

import(filename, options = {}) click to toggle source
# File lib/gd/image.rb, line 8
def import(filename, options = {})
  format = options.delete(:format)
  format = format.to_s.downcase if format
  raise ArgumentError, "Unsupported format '#{format}'" if format && !FORMATS.include?(format)
  format ||= format_from_filename(filename) || format_from_magic(File.binread(filename, 4))
  method = { PNG => :gdImageCreateFromPng, JPEG => :gdImageCreateFromJpeg, GIF => :gdImageCreateFromGif }[format]
  if ptr = File.open(filename, 'rb') { |f| GD::LIB.public_send(method, f) } and not ptr.null?
    ptr.free = GD::LIB['gdImageDestroy']
    struct = LIB::ImageStruct.new(ptr)
    if struct.trueColor.zero?
      IndexedColorImage.new(struct)
    else
      TrueColorImage.new(struct)
    end
  end
end