Fix error when image type not support by minimagick.

This commit is contained in:
邱博亞 2024-08-27 23:05:06 +08:00
parent c0bd6253e2
commit 6e9c00464d
1 changed files with 13 additions and 9 deletions

View File

@ -46,6 +46,7 @@ class PageContentsController < OrbitAdminController
image_file = Tempfile.new image_file = Tempfile.new
image_file.binmode image_file.binmode
image_file.write(res.body) image_file.write(res.body)
begin
image = MiniMagick::Image.open(image_file.path) image = MiniMagick::Image.open(image_file.path)
IMG_INFO[img_src] = {width: image[:width], height: image[:height]} IMG_INFO[img_src] = {width: image[:width], height: image[:height]}
if image[:width] if image[:width]
@ -56,6 +57,9 @@ class PageContentsController < OrbitAdminController
end end
image_file.close image_file.close
image_file.unlink image_file.unlink
rescue MiniMagick::Invalid => e
puts ["src = #{img_src}", e.to_s]
end
else else
IMG_INFO[img_src] = {} IMG_INFO[img_src] = {}
end end