Sha256: 9196a7877c2ceb2230ce410ec5f146dbccb9ac30abbf6574d396ff0d89e0daac
Contents?: true
Size: 1.41 KB
Versions: 4
Compression:
Stored size: 1.41 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, "rb") 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 load_data(png_file.read) else raise GIMPCanNotHandleError.new("gimp #{args.join(' ')}", GIMP_COMMANDS) end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
rabbit-3.0.3 | lib/rabbit/image/gimp.rb |
rabbit-3.0.2 | lib/rabbit/image/gimp.rb |
rabbit-3.0.1 | lib/rabbit/image/gimp.rb |
rabbit-3.0.0 | lib/rabbit/image/gimp.rb |