Commit eb83d16a by jyurek

More error checking

git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@183 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
parent 93710de5
...@@ -314,12 +314,17 @@ module Thoughtbot #:nodoc: ...@@ -314,12 +314,17 @@ module Thoughtbot #:nodoc:
def make_thumbnail attachment, orig_io, geometry def make_thumbnail attachment, orig_io, geometry
operator = geometry[-1,1] operator = geometry[-1,1]
geometry, crop_geometry = geometry_for_crop(geometry, orig_io) if operator == '#' geometry, crop_geometry = geometry_for_crop(geometry, orig_io) if operator == '#'
command = "convert - -scale '#{geometry}' #{operator == '#' ? "-crop '#{crop_geometry}'" : ""} -" begin
thumb = IO.popen(command, "w+") do |io| command = "convert - -scale '#{geometry}' #{operator == '#' ? "-crop '#{crop_geometry}'" : ""} -"
orig_io.rewind ActiveRecord::Base.logger.info("Thumbnail: '#{command}'")
io.write(orig_io.read) thumb = IO.popen(command, "w+") do |io|
io.close_write orig_io.rewind
StringIO.new(io.read) io.write(orig_io.read)
io.close_write
StringIO.new(io.read)
end
rescue SystemCallError => e
raise PaperclipError.new(attachment, "Error creating thumbnail. #{e}")
end end
if ::Thoughtbot::Paperclip.options[:whiny_thumbnails] if ::Thoughtbot::Paperclip.options[:whiny_thumbnails]
raise PaperclipError.new(attachment, "Convert returned with result code #{$?.exitstatus}: #{thumb.read}") unless $?.success? raise PaperclipError.new(attachment, "Convert returned with result code #{$?.exitstatus}: #{thumb.read}") unless $?.success?
...@@ -334,7 +339,7 @@ module Thoughtbot #:nodoc: ...@@ -334,7 +339,7 @@ module Thoughtbot #:nodoc:
io.close_write io.close_write
if match = io.read.split[2].match(/(\d+)x(\d+)/) if match = io.read.split[2].match(/(\d+)x(\d+)/)
src = match[1,2].map(&:to_f) src = match[1,2].map(&:to_f)
srch = src[0] > src[1] srch = src[0] > src[1]
dst = geometry.match(/(\d+)x(\d+)/)[1,2].map(&:to_f) dst = geometry.match(/(\d+)x(\d+)/)[1,2].map(&:to_f)
dsth = dst[0] > dst[1] dsth = dst[0] > dst[1]
ar = src[0] / src[1] ar = src[0] / src[1]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment