lib/image_optim/worker/jhead.rb in image_optim-0.17.1 vs lib/image_optim/worker/jhead.rb in image_optim-0.18.0

- old
+ new

@@ -20,17 +20,24 @@ def used_bins [:jhead, :jpegtran] end def optimize(src, dst) - if (2..8).include?(EXIFR::JPEG.new(src.to_s).orientation.to_i) - src.copy(dst) - args = %W[-autorot #{dst}] - resolve_bin!(:jpegtran) - execute(:jhead, *args) && dst.size? - else - false - end + return false unless oriented?(src) + src.copy(dst) + args = %W[ + -autorot + #{dst} + ] + resolve_bin!(:jpegtran) + execute(:jhead, *args) && dst.size? + end + + private + + def oriented?(image) + exif = EXIFR::JPEG.new(image.to_s) + (2..8).include?(exif.orientation.to_i) end end end end