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) ⇒ 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
24 25 26 |
# File 'lib/morandi/srgb_conversion.rb', line 24 def self.default_icc_path(path) "#{path}.icc.jpg" end |
.perform(path) ⇒ 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 22 |
# File 'lib/morandi/srgb_conversion.rb', line 10 def self.perform(path) return unless suitable_for_jpegicc?(path) icc_file_path = default_icc_path(path) system('jpgicc', '-q97', path, icc_file_path, out: '/dev/null', err: '/dev/null') unless valid_jpeg?(icc_file_path) FileUtils.rm_f(icc_file_path) # jpgicc likes to leave an empty file after failing return end icc_file_path end |
.suitable_for_jpegicc?(path) ⇒ Boolean
39 40 41 |
# File 'lib/morandi/srgb_conversion.rb', line 39 def self.suitable_for_jpegicc?(path) valid_jpeg?(path) end |
.valid_jpeg?(path) ⇒ Boolean
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/morandi/srgb_conversion.rb', line 28 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 |