getValue(Dimension::RATIO_ATTRIBUTE); if ($stringRatio === null) { return $selectedPageImage; } /** * We select the best image for the ratio * Best ratio */ $bestRatioDistance = 9999; try { $targetRatio = Dimension::convertTextualRatioToNumber($stringRatio); } catch (ExceptionBadSyntax $e) { LogUtility::error("The ratio ($stringRatio) is not a valid ratio. Error: {$e->getMessage()}", PageImageTag::CANONICAL); return $selectedPageImage; } $pageImages = $page->getPageMetadataImages(); foreach ($pageImages as $pageImage) { $path = $pageImage->getImagePath(); try { $fetcherImage = IFetcherLocalImage::createImageFetchFromPath($path); } catch (Exception $e) { LogUtility::msg("An image object could not be build from ($path). Is it an image file ?. Error: {$e->getMessage()}"); continue; } $ratioDistance = $targetRatio - $fetcherImage->getIntrinsicAspectRatio(); if ($ratioDistance < $bestRatioDistance) { $bestRatioDistance = $ratioDistance; $selectedPageImage = $fetcherImage; } } return $selectedPageImage; } /** * @throws ExceptionNotFound * @deprecated */ public static function createImageFetchFromPageImageMetadata(MarkupPath $page): IFetcherLocalImage { $selectedPageImage = null; foreach ($page->getPageMetadataImages() as $pageMetadataImage) { try { $pageMetadataImagePath = $pageMetadataImage->getImagePath(); $selectedPageImage = IFetcherLocalImage::createImageFetchFromPath($pageMetadataImagePath); } catch (\Exception $e) { LogUtility::internalError("The file ($pageMetadataImagePath) is not a valid image for the page ($page). Error: {$e->getMessage()}"); continue; } } if ($selectedPageImage !== null) { return $selectedPageImage; } throw new ExceptionNotFound("No page image metadata image could be found for the page ($page)"); } }