Sha256: cee96c0c1d727634e7589bcded9c9590a7c4ffe7ddaaca130b79f77c6541dca3

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

require "rabbit/utils"
require "rabbit/image/base"

module Rabbit
  module ImageManipulable
    class GIMP < Base

      unshift_loader(self)

      GIMP_COMMANDS = %w(gimp)
      HEADER = "gimp xcf file"
      HEADER_SIZE = HEADER.size

      include SystemRunner

      class << self
        def match?(filename)
          File.open(filename) do |f|
            HEADER == f.read(HEADER_SIZE)
          end
        end
      end

      private
      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
          @pixbuf = load_data(png_file.read)
        else
          raise GIMPCanNotHandleError.new("gimp #{args.join(' ')}",
                                          GIMP_COMMANDS)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rabbit-2.1.9 lib/rabbit/image/gimp.rb
rabbit-2.1.8 lib/rabbit/image/gimp.rb
rabbit-2.1.7 lib/rabbit/image/gimp.rb
rabbit-2.1.6 lib/rabbit/image/gimp.rb
rabbit-2.1.5 lib/rabbit/image/gimp.rb
rabbit-2.1.4 lib/rabbit/image/gimp.rb
rabbit-2.1.3 lib/rabbit/image/gimp.rb