Class: RubySpriter::GimpProcessor
- Inherits:
-
Object
- Object
- RubySpriter::GimpProcessor
- Defined in:
- lib/ruby_spriter/gimp_processor.rb
Overview
Processes images with GIMP
Constant Summary collapse
- DEFAULT_BG_THRESHOLD =
Default background color tolerance for selection operations (0-100 scale)
15.0
Instance Attribute Summary collapse
-
#gimp_path ⇒ Object
readonly
Returns the value of attribute gimp_path.
-
#gimp_version ⇒ Object
readonly
Returns the value of attribute gimp_version.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#execute_python_script(script, output_file) ⇒ Boolean
Execute a Python script with GIMP (used by ThresholdStepper).
-
#initialize(gimp_path, options = {}) ⇒ GimpProcessor
constructor
A new instance of GimpProcessor.
-
#process(input_file) ⇒ String
Process image with GIMP operations.
Constructor Details
#initialize(gimp_path, options = {}) ⇒ GimpProcessor
Returns a new instance of GimpProcessor.
14 15 16 17 18 |
# File 'lib/ruby_spriter/gimp_processor.rb', line 14 def initialize(gimp_path, = {}) @gimp_path = gimp_path @options = @gimp_version = [:gimp_version] || { major: 3, minor: 0 } # Default to GIMP 3 end |
Instance Attribute Details
#gimp_path ⇒ Object (readonly)
Returns the value of attribute gimp_path.
9 10 11 |
# File 'lib/ruby_spriter/gimp_processor.rb', line 9 def gimp_path @gimp_path end |
#gimp_version ⇒ Object (readonly)
Returns the value of attribute gimp_version.
9 10 11 |
# File 'lib/ruby_spriter/gimp_processor.rb', line 9 def gimp_version @gimp_version end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/ruby_spriter/gimp_processor.rb', line 9 def @options end |
Instance Method Details
#execute_python_script(script, output_file) ⇒ Boolean
Execute a Python script with GIMP (used by ThresholdStepper)
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ruby_spriter/gimp_processor.rb', line 59 def execute_python_script(script, output_file) script_file = File.join(Dir.tmpdir, "gimp_threshold_#{Time.now.to_i}_#{rand(10_000)}.py") log_file = File.join(Dir.tmpdir, "gimp_threshold_log_#{Time.now.to_i}_#{rand(10_000)}.txt") begin File.write(script_file, script) if [:debug] Utils::OutputFormatter.indent("DEBUG: Threshold script: #{script_file}") Utils::OutputFormatter.indent("DEBUG: Expected output: #{output_file}") end # Execute using existing platform-specific methods if Platform.windows? execute_gimp_windows(script_file, log_file) else execute_gimp_unix(script_file, log_file) end # Check if output was created if File.exist?(output_file) && File.size(output_file).positive? true else if [:debug] Utils::OutputFormatter.indent("WARNING: Threshold script did not produce output") end false end rescue StandardError => e if [:debug] Utils::OutputFormatter.indent("ERROR in threshold script: #{e.}") end false ensure cleanup_temp_files(script_file, log_file) unless [:keep_temp] end end |
#process(input_file) ⇒ String
Process image with GIMP operations
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ruby_spriter/gimp_processor.rb', line 23 def process(input_file) Utils::FileHelper.validate_readable!(input_file) Utils::OutputFormatter.header("GIMP Processing") # Inform about Xvfb usage on Linux if Platform.linux? Utils::OutputFormatter.note("Using GIMP via Xvfb (virtual display - no GUI windows)") end # Inform user if automatic operation order optimization is applied if [:scale_percent] && [:remove_bg] && [:operation_order] == :scale_then_remove_bg Utils::OutputFormatter.note("Auto-optimized: Removing background before scaling for better quality") end working_file = input_file operations = determine_operations # Execute operations in configured order operations.each do |operation| working_file = send(operation, working_file) end # Apply sharpening at the very end, after all GIMP operations if [:sharpen] working_file = apply_sharpen_imagemagick(working_file) end working_file end |