From 79923344d4f82da0db97c0a6d7bfb735c381134d Mon Sep 17 00:00:00 2001 From: Toks Date: Fri, 29 Mar 2013 10:47:18 -0400 Subject: [PATCH] fix unclosed files windows doesn't like them --- app/models/advertisement.rb | 8 +++++--- app/models/upload.rb | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/models/advertisement.rb b/app/models/advertisement.rb index 598baf62c..4b5dbf1ef 100644 --- a/app/models/advertisement.rb +++ b/app/models/advertisement.rb @@ -52,9 +52,11 @@ class Advertisement < ActiveRecord::Base end File.chmod(0644, image_path) - image_size = ImageSize.new(File.open(image_path, "rb")) - self.width = image_size.get_width - self.height = image_size.get_height + File.open(image_path, "rb") do |file| + image_size = ImageSize.new(file.read) + self.width = image_size.get_width + self.height = image_size.get_height + end if width > height self.ad_type = "horizontal" diff --git a/app/models/upload.rb b/app/models/upload.rb index d162de1a0..aa9c7e676 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -172,9 +172,11 @@ class Upload < ActiveRecord::Base module DimensionMethods # Figures out the dimensions of the image. def calculate_dimensions(file_path) - image_size = ImageSize.new(File.open(file_path, "rb")) - self.image_width = image_size.get_width - self.image_height = image_size.get_height + File.open(file_path, "rb") do |file| + image_size = ImageSize.new(file.read) + self.image_width = image_size.get_width + self.image_height = image_size.get_height + end end def add_dimension_tags!