From e6f4ed47e2fa4c57665fc81c97165f6e4a4c2a5f Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 23 Mar 2021 20:01:32 +0000 Subject: [PATCH 1/2] Avoid error "Uncaught ImagickException: Unable to scale image" --- src/Object/Image.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Object/Image.php b/src/Object/Image.php index d69b01ad4..c1da711f9 100644 --- a/src/Object/Image.php +++ b/src/Object/Image.php @@ -541,7 +541,12 @@ class Image do { // FIXME - implement horizontal bias for scaling as in following GD functions // to allow very tall images to be constrained only horizontally. - $this->image->scaleImage($dest_width, $dest_height); + try { + $this->image->scaleImage($dest_width, $dest_height); + } catch (Exception $e) { + // Imagick couldn't use the data + return false; + } } while ($this->image->nextImage()); // These may not be necessary anymore From fb663f0668c2ac09ba50e97ecbea302956ed1938 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 23 Mar 2021 20:03:08 +0000 Subject: [PATCH 2/2] Avoid several notices in ParseUrl --- src/Util/ParseUrl.php | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index d2986a362..1810293b7 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -512,19 +512,20 @@ class ParseUrl { if (!empty($siteinfo['images'])) { array_walk($siteinfo['images'], function (&$image) use ($page_url) { + $image = []; // According to the specifications someone could place a picture url into the content field as well. // But this doesn't seem to happen in the wild, so we don't cover it here. - $image['url'] = self::completeUrl($image['url'], $page_url); - $photodata = Images::getInfoFromURLCached($image['url']); - if (!empty($photodata) && ($photodata[0] > 50) && ($photodata[1] > 50)) { - $image['src'] = $image['url']; - $image['width'] = $photodata[0]; - $image['height'] = $photodata[1]; - $image['contenttype'] = $photodata['mime']; - unset($image['url']); - ksort($image); - } else { - $image = []; + if (!empty($image['url'])) { + $image['url'] = self::completeUrl($image['url'], $page_url); + $photodata = Images::getInfoFromURLCached($image['url']); + if (!empty($photodata) && ($photodata[0] > 50) && ($photodata[1] > 50)) { + $image['src'] = $image['url']; + $image['width'] = $photodata[0]; + $image['height'] = $photodata[1]; + $image['contenttype'] = $photodata['mime']; + unset($image['url']); + ksort($image); + } } }); @@ -542,7 +543,7 @@ class ParseUrl if (!empty($media[$field])) { $media[$field] = self::completeUrl($media[$field], $page_url); $type = self::getContentType($media[$field]); - if ($type[0] == 'text') { + if (($type[0] ?? '') == 'text') { if ($field == 'embed') { $embed = $media[$field]; } else { @@ -685,7 +686,9 @@ class ParseUrl { if (!empty($jsonld['@graph']) && is_array($jsonld['@graph'])) { foreach ($jsonld['@graph'] as $part) { - $siteinfo = self::parseParts($siteinfo, $part); + if (!empty($part)) { + $siteinfo = self::parseParts($siteinfo, $part); + } } } elseif (!empty($jsonld['@type'])) { $siteinfo = self::parseJsonLd($siteinfo, $jsonld); @@ -699,7 +702,9 @@ class ParseUrl } if ($numeric_keys) { foreach ($jsonld as $part) { - $siteinfo = self::parseParts($siteinfo, $part); + if (!empty($part)) { + $siteinfo = self::parseParts($siteinfo, $part); + } } } }