From 8850d99824c219bfa151e1070e9e36558eec72e6 Mon Sep 17 00:00:00 2001 From: chiu Date: Fri, 4 Oct 2024 06:51:10 +0000 Subject: [PATCH] fix svg file cannot open error, just skip get width or height --- app/controllers/page_contents_controller.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/controllers/page_contents_controller.rb b/app/controllers/page_contents_controller.rb index 95e6df5..12d7a84 100644 --- a/app/controllers/page_contents_controller.rb +++ b/app/controllers/page_contents_controller.rb @@ -30,12 +30,14 @@ class PageContentsController < OrbitAdminController img_src_path = File.join('public', img_src) img_src_path = URI.decode(img_src_path) if File.exist?(img_src_path) - image = MiniMagick::Image.open(img_src_path) - if image[:width] - metas << {"property" => "og:image:width", "content" => image[:width].to_s} - end - if image[:height] - metas << {"property" => "og:image:height", "content" => image[:height].to_s} + image = MiniMagick::Image.open(img_src_path) rescue nil + if image + if image[:width] + metas << {"property" => "og:image:width", "content" => image[:width].to_s} + end + if image[:height] + metas << {"property" => "og:image:height", "content" => image[:height].to_s} + end end end else