Class: ShotwellFS::Transform
- Inherits:
-
Object
- Object
- ShotwellFS::Transform
- Defined in:
- lib/shotwellfs/transform.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
Bump this if the transformation code changes in a way that would change the images
1
Instance Attribute Summary collapse
-
#crop ⇒ Object
readonly
Returns the value of attribute crop.
-
#redeye ⇒ Object
readonly
Returns the value of attribute redeye.
Instance Method Summary collapse
- #apply(input, output) ⇒ Object
- #generate_id(photo_id) ⇒ Object
- #has_transforms? ⇒ Boolean
-
#initialize(transformations) ⇒ Transform
constructor
A new instance of Transform.
- #to_s ⇒ Object
Constructor Details
#initialize(transformations) ⇒ Transform
Returns a new instance of Transform.
149 150 151 152 153 |
# File 'lib/shotwellfs/transform.rb', line 149 def initialize(transformations) doc = IniParse.parse(transformations) @crop = doc.has_section?("crop") ? Crop.new(doc["crop"]) : nil @redeye = doc.has_section?("redeye") ? RedEye.new(doc["redeye"]) : nil end |
Instance Attribute Details
#crop ⇒ Object (readonly)
Returns the value of attribute crop.
12 13 14 |
# File 'lib/shotwellfs/transform.rb', line 12 def crop @crop end |
#redeye ⇒ Object (readonly)
Returns the value of attribute redeye.
12 13 14 |
# File 'lib/shotwellfs/transform.rb', line 12 def redeye @redeye end |
Instance Method Details
#apply(input, output) ⇒ Object
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/shotwellfs/transform.rb', line 167 def apply(input,output) image = Magick::Image.read(input)[0] image.format = "JPG" redeye.apply(image) if redeye crop.apply(image) if crop image.write(output) image.destroy! end |
#generate_id(photo_id) ⇒ Object
159 160 161 162 163 164 165 |
# File 'lib/shotwellfs/transform.rb', line 159 def generate_id(photo_id) if has_transforms? Digest::MD5.hexdigest("#{photo_id}:#{self}") else nil end end |
#has_transforms? ⇒ Boolean
155 156 157 |
# File 'lib/shotwellfs/transform.rb', line 155 def has_transforms? ( crop || redeye ) && true end |
#to_s ⇒ Object
178 179 180 181 |
# File 'lib/shotwellfs/transform.rb', line 178 def to_s xforms = [ redeye, crop ].reject { |x| x.nil? }.join("\n ") "#{self.class.name}:#{VERSION}\n #{xforms}" end |