class Rabbit::ImageManipulable::GIMP

Constants

GIMP_COMMANDS
HEADER_SIZE

Public Class Methods

match?(filename) click to toggle source
# File lib/rabbit/image/gimp.rb, line 17
def match?(filename)
  File.open(filename, "rb") do |f|
    HEADER == f.read(HEADER_SIZE)
  end
end

Private Instance Methods

update_size() click to toggle source
# File lib/rabbit/image/gimp.rb, line 25
      def update_size
        png_file = Tempfile.new("rabbit-loader-gimp-png")
        png_path = png_file.path
        clip_to_image = 1
        merge_type = clip_to_image
        command = <<-EOC
(let ((image (car (gimp-file-load RUN-NONINTERACTIVE
                                  "#{@filename}" "#{@filename}"))))
  (let ((layer (car (gimp-image-merge-visible-layers image #{merge_type}))))
    (file-png-save-defaults RUN-NONINTERACTIVE image layer
                            "#{png_path}" "#{png_path}"))
  (gimp-image-delete image))
EOC
        args = %w(-i)
        args.concat(["-b", command])
        args.concat(["-b", "(gimp-quit TRUE)"])
        if GIMP_COMMANDS.any? {|gimp| run(gimp, *args); File.exist?(png_path)}
          png_file.open
          png_file.binmode
          load_data(png_file.read)
        else
          raise GIMPCanNotHandleError.new("gimp #{args.join(' ')}",
                                          GIMP_COMMANDS)
        end
      end