Skip to content

Instantly share code, notes, and snippets.

@alexkojin
Created April 12, 2010 04:17
Show Gist options
  • Save alexkojin/363267 to your computer and use it in GitHub Desktop.
Save alexkojin/363267 to your computer and use it in GitHub Desktop.
class ResizeImageError < StandardError;end
IMAGE_SIZE = "720x720>"
def resize_image
result_path = File.dirname(self.file_path) + "/#{self.user_id}_#{Time.now.to_i}_#{(rand * 10000000).to_i}.jpg"
cmd = %(convert -strip "#{self.file_path}" -resize "#{IMAGE_SIZE}" "#{result_path}")
output = `#{cmd}`
unless $?.exitstatus == 0
raise ResizeImageError, "Error while resize image #{cmd}"
end
self.file_path = result_path
self.file_size = File.size(result_path)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment