fix svg file cannot open error, just skip get width or height

This commit is contained in:
chiu 2024-10-04 06:51:10 +00:00
parent f682f99975
commit 8850d99824
1 changed files with 8 additions and 6 deletions

View File

@ -30,7 +30,8 @@ class PageContentsController < OrbitAdminController
img_src_path = File.join('public', img_src) img_src_path = File.join('public', img_src)
img_src_path = URI.decode(img_src_path) img_src_path = URI.decode(img_src_path)
if File.exist?(img_src_path) if File.exist?(img_src_path)
image = MiniMagick::Image.open(img_src_path) image = MiniMagick::Image.open(img_src_path) rescue nil
if image
if image[:width] if image[:width]
metas << {"property" => "og:image:width", "content" => image[:width].to_s} metas << {"property" => "og:image:width", "content" => image[:width].to_s}
end end
@ -38,6 +39,7 @@ class PageContentsController < OrbitAdminController
metas << {"property" => "og:image:height", "content" => image[:height].to_s} metas << {"property" => "og:image:height", "content" => image[:height].to_s}
end end
end end
end
else else
res = get_response(URI.parse(img_src)) res = get_response(URI.parse(img_src))
image = IMG_INFO[img_src] image = IMG_INFO[img_src]