FIX: need to reload the file once optimized

This commit is contained in:
Régis Hanol 2015-05-29 13:02:05 +02:00
parent 555b5cb055
commit 14a9a98c5b

@ -55,12 +55,14 @@ class OptimizedImage < ActiveRecord::Base
url: "", url: "",
) )
# store the optimized image and update its url # store the optimized image and update its url
url = Discourse.store.store_optimized_image(temp_file, thumbnail) File.open(temp_path) do |file|
if url.present? url = Discourse.store.store_optimized_image(file, thumbnail)
thumbnail.url = url if url.present?
thumbnail.save thumbnail.url = url
else thumbnail.save
Rails.logger.error("Failed to store avatar #{size} for #{upload.url} from #{source}") else
Rails.logger.error("Failed to store optimized image #{width}x#{height} for #{upload.url}")
end
end end
else else
Rails.logger.error("Failed to create optimized image #{width}x#{height} for #{upload.url}") Rails.logger.error("Failed to create optimized image #{width}x#{height} for #{upload.url}")
@ -159,16 +161,13 @@ class OptimizedImage < ActiveRecord::Base
def self.convert_with(instructions, to) def self.convert_with(instructions, to)
`convert #{instructions.join(" ")}` `convert #{instructions.join(" ")}`
return false if $?.exitstatus != 0 return false if $?.exitstatus != 0
begin ImageOptim.new.optimize_image!(to)
ImageOptim.new.optimize_image!(to)
rescue => ex
Rails.logger.warn("Could not optimize image: #{to}")
end
true true
rescue
Rails.logger.error("Could not optimize image: #{to}")
false
end end
end end