Class: Morandi::SrgbConversion
- Inherits:
-
Object
- Object
- Morandi::SrgbConversion
- Defined in:
- lib/morandi/srgb_conversion.rb
Overview
Converts the file under ‘path` to sRGB colour space
Class Method Summary collapse
- .default_icc_path(path) ⇒ Object
-
.perform(path, target_path: nil) ⇒ Object
Performs a conversion to srgb colour space if possible Returns a path to converted file on success or nil on failure.
- .suitable_for_jpegicc?(path) ⇒ Boolean
- .valid_jpeg?(path) ⇒ Boolean
Class Method Details
.default_icc_path(path) ⇒ Object
23 24 25 |
# File 'lib/morandi/srgb_conversion.rb', line 23 def self.default_icc_path(path) "#{path}.icc.jpg" end |
.perform(path, target_path: nil) ⇒ Object
Performs a conversion to srgb colour space if possible Returns a path to converted file on success or nil on failure
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/morandi/srgb_conversion.rb', line 10 def self.perform(path, target_path: nil) return unless suitable_for_jpegicc?(path) icc_file_path = target_path || default_icc_path(path) return icc_file_path if valid_jpeg?(icc_file_path) system('jpgicc', '-q97', path, icc_file_path, out: '/dev/null', err: '/dev/null') return unless valid_jpeg?(icc_file_path) icc_file_path end |
.suitable_for_jpegicc?(path) ⇒ Boolean
38 39 40 |
# File 'lib/morandi/srgb_conversion.rb', line 38 def self.suitable_for_jpegicc?(path) valid_jpeg?(path) end |
.valid_jpeg?(path) ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/morandi/srgb_conversion.rb', line 27 def self.valid_jpeg?(path) return false unless File.exist?(path) return false unless File.size(path).positive? type, = GdkPixbuf::Pixbuf.get_file_info(path) type && type.name.eql?('jpeg') rescue StandardError false end |