From a8da5b1b723eafb179d95fef097190c5f7e14a56 Mon Sep 17 00:00:00 2001 From: Andrew Collins Date: Thu, 27 Mar 2014 17:25:09 -0400 Subject: [PATCH] Get image dimensions without EXIF extension Use `getimagesize` when `exif_imagetype` doesn't exist. --- src/PhpWord/Section/Image.php | 7 ++++++- src/PhpWord/Writer/Word2007.php | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Section/Image.php b/src/PhpWord/Section/Image.php index 931f906fe7..ad625a7b5d 100755 --- a/src/PhpWord/Section/Image.php +++ b/src/PhpWord/Section/Image.php @@ -132,7 +132,12 @@ public function __construct($source, $style = null, $isWatermark = false) throw new InvalidImageException; } $imgData = getimagesize($source); - $this->imageType = exif_imagetype($source); + if (function_exists('exif_imagetype')) { + $this->imageType = exif_imagetype($source); + } else { + $tmp = getimagesize($source); + $this->imageType = $tmp[2]; + } if (!in_array($this->imageType, $supportedTypes)) { throw new UnsupportedImageTypeException; } diff --git a/src/PhpWord/Writer/Word2007.php b/src/PhpWord/Writer/Word2007.php index fcd562ab14..33ff190c1b 100755 --- a/src/PhpWord/Writer/Word2007.php +++ b/src/PhpWord/Writer/Word2007.php @@ -270,7 +270,12 @@ private function checkContentTypes($src) if (stripos(strrev($src), strrev('.php')) === 0) { $extension = 'php'; } else { - $imageType = exif_imagetype($src); + if (function_exists('exif_imagetype')) { + $imageType = exif_imagetype($src); + } else { + $tmp = getimagesize($src); + $imageType = $tmp[2]; + } if ($imageType === \IMAGETYPE_JPEG) { $extension = 'jpg'; } elseif ($imageType === \IMAGETYPE_GIF) {