class GdkPixbuf::Pixbuf

Public Class Methods

new(*args, &block) click to toggle source
Calls superclass method
# File gdk_pixbuf2/lib/gdk_pixbuf2/deprecated.rb, line 26
def new(*args, &block)
  if args[0].is_a?(Pixbuf)
    message = "#{caller[0]}: #{self}.new(pixbuf, ...) is deprecated. "
    message << "Use pixbuf.new_subpixbuf(...)  instead."
    warn(message)
    args[0].new_subpixbuf(*args[1..-1])
  elsif args.size == 1 and args[0].is_a?(Hash)
    options = args[0]
    src_pixbuf = options[:src_pixbuf]
    if src_pixbuf
      message = "#{caller[0]}: "
      message << "#{self}.new(:src_pixbuf => pixbuf, ...) is deprecated. "
      message << "Use pixbuf.new_subpixbuf(...)  instead."
      warn(message)
      src_pixbuf.new_subpixbuf(options[:src_x],
                               options[:src_y],
                               options[:width],
                               options[:height])
    else
      super
    end
  else
    super
  end
end
new(*args) click to toggle source
Calls superclass method
# File gdk_pixbuf2/lib/gdk_pixbuf2/pixbuf.rb, line 21
def initialize(*args)
  case args.size
  when 1
    case args[0]
    when Hash
      initialize_with_hash(args[0])
    when String
      message = "#{caller[0]}: #{self.class}.new(path) is deprecated. "
      message << "Use #{self.class}.new(:file => path) instead."
      warn message
      initialize_raw(args[0])
    when Array
      message = "#{caller[0]}: #{self.class}.new(xpm) is deprecated. "
      message << "Use #{self.class}.new(:xpm => xpm) instead."
      warn message
      initialize_new_from_xpm_data(args[0])
    else
      raise ArgumentError, "must be options: #{args[0].inspect}"
    end
  when 2
    message = "#{caller[0]}: "
    message << "#{self.class}.new(data, copy_pixels) is deprecated. "
    message << "Use Gio::Resource instead."
    warn message
    initialize_from_inline(*args)
  when 3
    message = "#{caller[0]}: "
    message << "#{self.class}.new(path, width, height) is deprecated. "
    message << "Use #{self.class}.new(:file => path, :width => width, "
    message << ":height => height) instead."
    warn message
    initialize_new_from_file_at_size(*args)
  when 4
    message = "#{caller[0]}: "
    message << "#{self.class}.new(path, width, height, "
    message << "preserve_aspect_ratio) is deprecated. "
    message << "Use #{self.class}.new(:file => path, :width => width, "
    message << ":height => height, "
    message << ":preserve_aspect_ratio => preserve_aspect_ratio) instead."
    warn message
    initialize_new_from_file_at_scale(*args)
  when 5
    message = "#{caller[0]}: "
    message << "#{self.class}.new(colorspace, has_alpha, bits_per_sample, "
    message << "width, height) is deprecated."
    message << "Use #{self.class}.new(:colorspace => colorspace, "
    message << ":has_alpha => has_alpha, "
    message << ":bits_per_sample => bits_per_sample, "
    message << ":width => width, "
    message << ":height => height) instead."
    warn message
    initialize_new(*args)
  when 7
    message = "#{caller[0]}: "
    message << "#{self.class}.new(data, colorspace, has_alpha, "
    message << "bits_per_sample, width, height) is deprecated."
    message << "Use #{self.class}.new(:data => data, "
    message << ":colorspace => colorspace, "
    message << ":has_alpha => has_alpha, "
    message << ":bits_per_sample => bits_per_sample, "
    message << ":width => width, "
    message << ":height => height) instead."
    warn message
    initialize_new_from_data(*args)
  else
    super
  end
end
Also aliased as: initialize_raw

Public Instance Methods

composite(options) click to toggle source
# File gdk_pixbuf2/lib/gdk_pixbuf2/pixbuf.rb, line 288
def composite(options)
  destination = options[:destination] || options[:dest]
  dest_x = options[:destination_x] || options[:dest_x] || 0
  dest_y = options[:destination_y] || options[:dest_y] || 0
  dest_width = options[:destination_width] || options[:dest_width]
  dest_height = options[:destination_height] || options[:dest_height]

  destination ||= Pixbuf.new(colorspace,
                             has_alpha?,
                             bits_per_sample,
                             dest_x + dest_width,
                             dest_y + dest_height)
  destination.composite!(self, options)
  destination
end
Also aliased as: composite_raw
composite!(source, options) click to toggle source
# File gdk_pixbuf2/lib/gdk_pixbuf2/pixbuf.rb, line 304
def composite!(source, options)
  dest_x = options[:destination_x] || options[:dest_x] || 0
  dest_y = options[:destination_y] || options[:dest_y] || 0
  dest_width = options[:destination_width] || options[:dest_width]
  dest_height = options[:destination_height] || options[:dest_height]
  offset_x = options[:offset_x] || 0.0
  offset_y = options[:offset_y] || 0.0
  scale_x = options[:scale_x] || (dest_width / source.width.to_f)
  scale_y = options[:scale_y] || (dest_height / source.height.to_f)
  interpolation_type = options[:interpolation_type] ||
    options[:interp_type] ||
    :bilinear
  overall_alpha = options[:overall_alpha] || 255
  check_x = options[:check_x] || 0
  check_y = options[:check_y] || 0
  check_size = options[:check_size]
  color1 = options[:color1] || 0x999999
  color2 = options[:color2] || 0xdddddd

  if check_size
    source.composite_color(self,
                           dest_x,
                           dest_y,
                           dest_width,
                           dest_height,
                           offset_x,
                           offset_y,
                           scale_x,
                           scale_y,
                           interpolation_type,
                           overall_alpha,
                           check_x,
                           check_y,
                           check_size,
                           color1,
                           color2)
  else
    source.composite_raw(self,
                         dest_x,
                         dest_y,
                         dest_width,
                         dest_height,
                         offset_x,
                         offset_y,
                         scale_x,
                         scale_y,
                         interpolation_type,
                         overall_alpha)
  end
end
composite_raw(options)
Alias for: composite
dup() click to toggle source
# File gdk_pixbuf2/lib/gdk_pixbuf2/pixbuf.rb, line 173
def dup
  copy
end
fill!(pixel) click to toggle source
# File gdk_pixbuf2/lib/gdk_pixbuf2/pixbuf.rb, line 183
def fill!(pixel)
  fill(pixel)
end
initialize_raw(*args)
Alias for: new
rotate(angle) click to toggle source
# File gdk_pixbuf2/lib/gdk_pixbuf2/pixbuf.rb, line 187
def rotate(angle)
  rotate_simple(angle)
end
saturate_and_pixelate(saturation, pixelate) click to toggle source
# File gdk_pixbuf2/lib/gdk_pixbuf2/pixbuf.rb, line 192
def saturate_and_pixelate(saturation, pixelate)
  dest = dup
  saturate_and_pixelate_raw(dest, saturation, pixelate)
  dest
end
Also aliased as: saturate_and_pixelate_raw
saturate_and_pixelate_raw(saturation, pixelate)
save(*args) click to toggle source

@overload save(type, options={})

Save as `type` format.

@param type [String] The format to be saved. `"jpeg"`,
  `"png"`, `"ico"` and `"bmp"` are available by default.

@param options [Hash<Symbol, String>] The options for
  saving. Key-value pairs except `:filename` key are passed to
  save logic. Available keys are depended on format. For
  example, `:quality => "100"` is available in `"jpeg"`
  format.
@option options [String] :filename The filename to be outputted.

@return [String, void] The saved data. If you specify
  `:filename` option, it returns nothing.

@overload save(filename, type, options={})

Save to `filename` as `type` format.

@return [void]

@deprecated since 3.1.1. Use `save(type, :filename =>
  filename)` instead.
# File gdk_pixbuf2/lib/gdk_pixbuf2/pixbuf.rb, line 223
def save(*args)
  case args.size
  when 1
    filename = nil
    type, = args
    options = {}
  when 2
    if args.last.is_a?(Hash)
      type, options = args
      if options.key?(:filename)
        options = options.dup
        filename = options.delete(:filename)
      else
        filename = nil
      end
    else
      filename, type = args
      options = {}
    end
  when 3
    filename, type, options = args
  else
    message = "wrong number of arguments (given #{args.size}, expected 1..3)"
    raise ArgumentError, message
  end

  keys = []
  values = []
  options.each do |key, value|
    key = key.to_s if key.is_a?(Symbol)
    keys << key
    values << value
  end
  if filename
    savev(filename, type, keys, values)
  else
    _, data = save_to_bufferv(type, keys, values)
    data.pack("C*")
  end
end
scale(*args) click to toggle source

TODO: test TODO: Improve API by Hash

# File gdk_pixbuf2/lib/gdk_pixbuf2/pixbuf.rb, line 267
def scale(*args)
  case args.size
  when 2, 3
    width, height, interp_type = args
    interp_type ||= :bilinear
    scale_simple(width, height, interp_type)
  else
    scale_raw(*args)
  end
end
Also aliased as: scale_raw
scale!(source, *args) click to toggle source

TODO: test TODO: Improve API by Hash

# File gdk_pixbuf2/lib/gdk_pixbuf2/pixbuf.rb, line 280
def scale!(source, *args)
  if args.size == 8
    args << :bilinear
  end
  source.scale_raw(self, *args)
end
scale_raw(*args)
Alias for: scale