16 use Psr\Log\LoggerAwareInterface;
17 use Psr\Log\LoggerAwareTrait;
64 if (function_exists(
'getimagesize')) {
65 $size = @getimagesize($imageFile);
67 if ($size ===
false) {
70 [$width, $height] = $size;
72 if (function_exists(
'exif_read_data')) {
73 $exif = @exif_read_data($imageFile);
75 if (isset($exif[
'Orientation']) && $exif[
'Orientation'] >= 5 && $exif[
'Orientation'] <= 8) {
76 return [$height, $width];
80 return [$width, $height];
88 if ($this->imageSizes ===
null) {
92 if ($this->imageSizes ===
false && $this->
getMimeType() ===
'image/svg+xml') {
96 if ($this->imageSizes ===
false) {
97 $graphicalFunctions = GeneralUtility::makeInstance(GraphicalFunctions::class);
98 $this->imageSizes = $graphicalFunctions->imageMagickIdentify($this->getPathname());
102 if (empty($this->imageSizes)) {
103 $this->logger->warning(
'I could not retrieve the image size for file ' . $this->getPathname());
104 $this->imageSizes = [0, 0];
120 $fileContent = file_get_contents($this->getPathname());
122 $previousValueOfEntityLoader = libxml_disable_entity_loader(
true);
123 $xml = simplexml_load_string($fileContent,
'SimpleXMLElement', LIBXML_NOERROR | LIBXML_NOWARNING);
126 if ($xml ===
false) {
130 libxml_disable_entity_loader($previousValueOfEntityLoader);
131 $xmlAttributes = $xml->attributes();
134 if (!empty($xmlAttributes[
'width']) && !empty($xmlAttributes[
'height'])) {
135 $imagesSizes = [(int)$xmlAttributes[
'width'], (
int)$xmlAttributes[
'height']];
136 } elseif (!empty($xmlAttributes[
'viewBox'])) {
138 $viewBox = explode(
' ', $xmlAttributes[
'viewBox']);
139 $imagesSizes = [(int)$viewBox[2], (
int)$viewBox[3]];
142 return $imagesSizes !== [] ? $imagesSizes :
false;