diff --git a/Classes/PHPWord/Media.php b/Classes/PHPWord/Media.php index 03328184..5fac968b 100755 --- a/Classes/PHPWord/Media.php +++ b/Classes/PHPWord/Media.php @@ -101,7 +101,7 @@ class PHPWord_Media $media['createfunction'] = $memoryImage->getImageCreateFunction(); $media['imagefunction'] = $memoryImage->getImageFunction(); } else { - $imageType = exif_imagetype($src); + $imageType = PHPWord_Shared_File::imagetype($src); if ($imageType === IMAGETYPE_JPEG) { $extension = 'jpg'; } elseif ($imageType === IMAGETYPE_GIF) { diff --git a/Classes/PHPWord/Section/Image.php b/Classes/PHPWord/Section/Image.php index fcaa1cc9..b8272e89 100755 --- a/Classes/PHPWord/Section/Image.php +++ b/Classes/PHPWord/Section/Image.php @@ -61,7 +61,6 @@ class PHPWord_Section_Image */ private $_isWatermark; - /** * Create a new Image * @@ -78,7 +77,7 @@ class PHPWord_Section_Image throw new InvalidImageException; } - if (!in_array(exif_imagetype($src), $supportedImageTypes)) { + if (!in_array(PHPWord_Shared_File::imagetype($src), $supportedImageTypes)) { throw new UnsupportedImageTypeException; } diff --git a/Classes/PHPWord/Shared/File.php b/Classes/PHPWord/Shared/File.php index 26a206ba..43b0cad4 100755 --- a/Classes/PHPWord/Shared/File.php +++ b/Classes/PHPWord/Shared/File.php @@ -33,12 +33,11 @@ class PHPWord_Shared_File /** * Verify if a file exists * - * @param string $pFilename Filename + * @param string $pFilename Filename * @return bool */ public static function file_exists($pFilename) { - // Regular file_exists return file_exists($pFilename); } @@ -50,18 +49,13 @@ class PHPWord_Shared_File */ public static function realpath($pFilename) { - // Returnvalue - $returnValue = ''; - - // Try using realpath() $returnValue = realpath($pFilename); - // Found something? - if ($returnValue == '' || is_null($returnValue)) { + if (!$returnValue) { $pathArray = explode('/', $pFilename); - while (in_array('..', $pathArray) && $pathArray[0] != '..') { + while (in_array('..', $pathArray) && $pathArray[0] !== '..') { for ($i = 0; $i < count($pathArray); ++$i) { - if ($pathArray[$i] == '..' && $i > 0) { + if ($pathArray[$i] === '..' && $i > 0) { unset($pathArray[$i]); unset($pathArray[$i - 1]); break; @@ -71,7 +65,36 @@ class PHPWord_Shared_File $returnValue = implode('/', $pathArray); } - // Return return $returnValue; } -} + + /** + * PHP Words version of exif_imagetype to return the Image Type from a file + * + * @param string $filename + * @return int|bool + */ + public static function PHPWord_imagetype($filename) + { + if ((list($width, $height, $type, $attr) = getimagesize($filename)) !== false) { + return $type; + } + return false; + } + + /** + * Return the Image Type from a file + * + * @param string $filename + * @return int|bool + */ + public static function imagetype($filename) + { + if (function_exists('exif_imagetype')) { + return exif_imagetype($filename); + } else { + return self::PHPWord_imagetype($filename); + } + return false; + } +} \ No newline at end of file diff --git a/Classes/PHPWord/Writer/Word2007.php b/Classes/PHPWord/Writer/Word2007.php index e62341bf..110ba392 100755 --- a/Classes/PHPWord/Writer/Word2007.php +++ b/Classes/PHPWord/Writer/Word2007.php @@ -212,7 +212,7 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter if (stripos(strrev($src), strrev('.php')) === 0) { $extension = 'php'; } else { - $imageType = exif_imagetype($src); + $imageType = PHPWord_Shared_File::imagetype($src); if ($imageType === IMAGETYPE_JPEG) { $extension = 'jpg'; } elseif ($imageType === IMAGETYPE_GIF) {