import (GD2::Image)

    # File lib/gd2/image.rb, line 155
        def self.import(filename, options = {})
          unless format = options.delete(:format)
            md = filename.match /\.([^.]+)\z/
            format = md ? md[1].downcase : nil
          end
          format = format.to_sym if format

          if format == :xpm
            raise ArgumentError, "Unexpected options #{options.inspect}" unless
              options.empty?
            ptr = SYM[:gdImageCreateFromXpm].call(filename)[0]
          elsif format == :gd2 && !options.empty?
            x, y, width, height =
              options.delete(:x) || 0, options.delete(:y) || 0,
              options.delete(:width)  || options.delete(:w),
              options.delete(:height) || options.delete(:h)
            raise ArgumentError, "Unexpected options #{options.inspect}" unless
              options.empty?
            raise ArgumentError, 'Missing required option :width' if width.nil?
            raise ArgumentError, 'Missing required option :height' if height.nil?
            ptr = File.open(filename, 'rb') do |file|
              SYM[:gdImageCreateFromGd2Part].call(file, x, y, width, height)[0]
            end
          else
            raise ArgumentError, "Unexpected options #{options.inspect}" unless
              options.empty?
            create_sym = {
              :jpeg => :gdImageCreateFromJpeg,
              :jpg  => :gdImageCreateFromJpeg,
              :png  => :gdImageCreateFromPng,
              :gif  => :gdImageCreateFromGif,
              :wbmp => :gdImageCreateFromWBMP,
              :gd   => :gdImageCreateFromGd,
              :gd2  => :gdImageCreateFromGd2,
              :xbm  => :gdImageCreateFromXbm
            }[format]
            raise UnrecognizedImageTypeError,
              'Format (or file extension) is not recognized' unless create_sym
            ptr = File.open(filename, 'rb') { |file| SYM[create_sym].call(file)[0] }
          end
          raise LibraryError unless ptr

          init_image_ptr(ptr)

          image = (image_true_color?(ptr) ?
            TrueColor : IndexedColor).allocate.init_with_image(ptr)

          block_given? ? yield(image) : image
        end