Merge pull request #11975 from owncloud/Combustible-combustible_dev

Check imagecreate*() return before using and use logger in \OC_Image
This commit is contained in:
Morris Jobke 2014-12-02 16:18:00 +01:00
commit a16d1a85ef
1 changed files with 267 additions and 254 deletions

View File

@ -6,20 +6,12 @@
* @author Thomas Tanghus
* @copyright 2011 Thomas Tanghus <thomas@tanghus.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*
*/
/**
* Class for basic image manipulation
*/
@ -32,8 +24,14 @@ class OC_Image {
private $fileInfo;
/**
* @var \OCP\ILogger
*/
private $logger;
/**
* Get mime type for an image file.
*
* @param string|null $filePath The path to a local image file.
* @return string The mime type if the it could be determined, otherwise an empty string.
*/
@ -49,14 +47,19 @@ class OC_Image {
/**
* Constructor.
*
* @param resource|string $imageRef The path to a local file, a base64 encoded string or a resource created by
* an imagecreate* function.
* @return \OC_Image False on error
* @param \OCP\ILogger $logger
*/
public function __construct($imageRef = null) {
//OC_Log::write('core',__METHOD__.'(): start', OC_Log::DEBUG);
public function __construct($imageRef = null, $logger = null) {
$this->logger = $logger;
if (is_null($logger)) {
$this->logger = \OC::$server->getLogger();
}
if (!extension_loaded('gd') || !function_exists('gd_info')) {
OC_Log::write('core', __METHOD__.'(): GD module not installed', OC_Log::ERROR);
$this->logger->error(__METHOD__ . '(): GD module not installed', array('app' => 'core'));
return false;
}
@ -71,6 +74,7 @@ class OC_Image {
/**
* Determine whether the object contains an image resource.
*
* @return bool
*/
public function valid() { // apparently you can't name a method 'empty'...
@ -79,6 +83,7 @@ class OC_Image {
/**
* Returns the MIME type of the image or an empty string if no image is loaded.
*
* @return string
*/
public function mimeType() {
@ -87,6 +92,7 @@ class OC_Image {
/**
* Returns the width of the image or -1 if no image is loaded.
*
* @return int
*/
public function width() {
@ -95,6 +101,7 @@ class OC_Image {
/**
* Returns the height of the image or -1 if no image is loaded.
*
* @return int
*/
public function height() {
@ -103,11 +110,12 @@ class OC_Image {
/**
* Returns the width when the image orientation is top-left.
*
* @return int
*/
public function widthTopLeft() {
$o = $this->getOrientation();
OC_Log::write('core', 'OC_Image->widthTopLeft() Orientation: '.$o, OC_Log::DEBUG);
$this->logger->debug('OC_Image->widthTopLeft() Orientation: ' . $o, array('app' => 'core'));
switch ($o) {
case -1:
case 1:
@ -126,11 +134,12 @@ class OC_Image {
/**
* Returns the height when the image orientation is top-left.
*
* @return int
*/
public function heightTopLeft() {
$o = $this->getOrientation();
OC_Log::write('core', 'OC_Image->heightTopLeft() Orientation: '.$o, OC_Log::DEBUG);
$this->logger->debug('OC_Image->heightTopLeft() Orientation: ' . $o, array('app' => 'core'));
switch ($o) {
case -1:
case 1:
@ -149,6 +158,7 @@ class OC_Image {
/**
* Outputs the image.
*
* @param string $mimeType
* @return bool
*/
@ -162,6 +172,7 @@ class OC_Image {
/**
* Saves the image.
*
* @param string $filePath
* @param string $mimeType
* @return bool
@ -172,7 +183,7 @@ class OC_Image {
$mimeType = $this->mimeType();
}
if ($filePath === null && $this->filePath === null) {
OC_Log::write('core', __METHOD__.'(): called with no path.', OC_Log::ERROR);
$this->logger->error(__METHOD__ . '(): called with no path.', array('app' => 'core'));
return false;
} elseif ($filePath === null && $this->filePath !== null) {
$filePath = $this->filePath;
@ -182,6 +193,7 @@ class OC_Image {
/**
* Outputs/saves the image.
*
* @param string $filePath
* @param string $mimeType
* @return bool
@ -192,12 +204,10 @@ class OC_Image {
if (!file_exists(dirname($filePath)))
mkdir(dirname($filePath), 0777, true);
if (!is_writable(dirname($filePath))) {
OC_Log::write('core',
__METHOD__.'(): Directory \''.dirname($filePath).'\' is not writable.',
OC_Log::ERROR);
$this->logger->error(__METHOD__ . '(): Directory \'' . dirname($filePath) . '\' is not writable.', array('app' => 'core'));
return false;
} elseif (is_writable(dirname($filePath)) && file_exists($filePath) && !is_writable($filePath)) {
OC_Log::write('core', __METHOD__.'(): File \''.$filePath.'\' is not writable.', OC_Log::ERROR);
$this->logger->error(__METHOD__ . '(): File \'' . $filePath . '\' is not writable.', array('app' => 'core'));
return false;
}
}
@ -289,11 +299,11 @@ class OC_Image {
break;
default:
$res = imagepng($this->resource);
OC_Log::write('core', 'OC_Image->data. Couldn\'t guess mimetype, defaulting to png', OC_Log::INFO);
$this->logger->info('OC_Image->data. Could not guess mime-type, defaulting to png', array('app' => 'core'));
break;
}
if (!$res) {
OC_Log::write('core', 'OC_Image->data. Error getting image data.', OC_Log::ERROR);
$this->logger->error('OC_Image->data. Error getting image data.', array('app' => 'core'));
}
return ob_get_clean();
}
@ -308,23 +318,24 @@ class OC_Image {
/**
* (I'm open for suggestions on better method name ;)
* Get the orientation based on EXIF data.
*
* @return int The orientation or -1 if no EXIF data is available.
*/
public function getOrientation() {
if ($this->imageType !== IMAGETYPE_JPEG) {
OC_Log::write('core', 'OC_Image->fixOrientation() Image is not a JPEG.', OC_Log::DEBUG);
$this->logger->debug('OC_Image->fixOrientation() Image is not a JPEG.', array('app' => 'core'));
return -1;
}
if (!is_callable('exif_read_data')) {
OC_Log::write('core', 'OC_Image->fixOrientation() Exif module not enabled.', OC_Log::DEBUG);
$this->logger->debug('OC_Image->fixOrientation() Exif module not enabled.', array('app' => 'core'));
return -1;
}
if (!$this->valid()) {
OC_Log::write('core', 'OC_Image->fixOrientation() No image loaded.', OC_Log::DEBUG);
$this->logger->debug('OC_Image->fixOrientation() No image loaded.', array('app' => 'core'));
return -1;
}
if (is_null($this->filePath) || !is_readable($this->filePath)) {
OC_Log::write('core', 'OC_Image->fixOrientation() No readable file path set.', OC_Log::DEBUG);
$this->logger->debug('OC_Image->fixOrientation() No readable file path set.', array('app' => 'core'));
return -1;
}
$exif = @exif_read_data($this->filePath, 'IFD0');
@ -340,11 +351,12 @@ class OC_Image {
/**
* (I'm open for suggestions on better method name ;)
* Fixes orientation based on EXIF data.
*
* @return bool.
*/
public function fixOrientation() {
$o = $this->getOrientation();
OC_Log::write('core', 'OC_Image->fixOrientation() Orientation: '.$o, OC_Log::DEBUG);
$this->logger->debug('OC_Image->fixOrientation() Orientation: ' . $o, array('app' => 'core'));
$rotate = 0;
switch ($o) {
case -1:
@ -384,15 +396,15 @@ class OC_Image {
$this->resource = $res;
return true;
} else {
OC_Log::write('core', 'OC_Image->fixOrientation() Error during alphasaving.', OC_Log::DEBUG);
$this->logger->debug('OC_Image->fixOrientation() Error during alpha-saving', array('app' => 'core'));
return false;
}
} else {
OC_Log::write('core', 'OC_Image->fixOrientation() Error during alphablending.', OC_Log::DEBUG);
$this->logger->debug('OC_Image->fixOrientation() Error during alpha-blending', array('app' => 'core'));
return false;
}
} else {
OC_Log::write('core', 'OC_Image->fixOrientation() Error during oriention fixing.', OC_Log::DEBUG);
$this->logger->debug('OC_Image->fixOrientation() Error during orientation fixing', array('app' => 'core'));
return false;
}
}
@ -401,6 +413,7 @@ class OC_Image {
/**
* Loads an image from a local file, a base64 encoded string or a resource created by an imagecreate* function.
*
* @param resource|string $imageRef The path to a local file, a base64 encoded string or a resource created by an imagecreate* function or a file resource (file handle ).
* @return resource|false An image resource or false on error
*/
@ -418,35 +431,36 @@ class OC_Image {
return $this->resource;
} elseif ($this->loadFromData($imageRef) !== false) {
return $this->resource;
} else {
OC_Log::write('core', __METHOD__.'(): couldn\'t load anything. Giving up!', OC_Log::DEBUG);
return false;
}
$this->logger->debug(__METHOD__ . '(): could not load anything. Giving up!', array('app' => 'core'));
return false;
}
/**
* Loads an image from an open file handle.
* It is the responsibility of the caller to position the pointer at the correct place and to close the handle again.
*
* @param resource $handle
* @return resource|false An image resource or false on error
*/
public function loadFromFileHandle($handle) {
OC_Log::write('core', __METHOD__.'(): Trying', OC_Log::DEBUG);
$contents = stream_get_contents($handle);
if ($this->loadFromData($contents)) {
return $this->resource;
}
return false;
}
/**
* Loads an image from a local file.
*
* @param bool|string $imagePath The path to a local file.
* @return bool|resource An image resource or false on error
*/
public function loadFromFile($imagePath = false) {
// exif_imagetype throws "read error!" if file is less than 12 byte
if (!@is_file($imagePath) || !file_exists($imagePath) || filesize($imagePath) < 12 || !is_readable($imagePath)) {
OC_Log::write('core', 'OC_Image->loadFromFile, couldn\'t load: ' . (string) urlencode($imagePath), OC_Log::DEBUG);
$this->logger->debug('OC_Image->loadFromFile, could not load: ' . (string)urlencode($imagePath), array('app' => 'core'));
return false;
}
$iType = exif_imagetype($imagePath);
@ -458,18 +472,14 @@ class OC_Image {
imagealphablending($this->resource, true);
imagesavealpha($this->resource, true);
} else {
OC_Log::write('core',
'OC_Image->loadFromFile, GIF images not supported: '.$imagePath,
OC_Log::DEBUG);
$this->logger->debug('OC_Image->loadFromFile, GIF images not supported: ' . $imagePath, array('app' => 'core'));
}
break;
case IMAGETYPE_JPEG:
if (imagetypes() & IMG_JPG) {
$this->resource = imagecreatefromjpeg($imagePath);
} else {
OC_Log::write('core',
'OC_Image->loadFromFile, JPG images not supported: '.$imagePath,
OC_Log::DEBUG);
$this->logger->debug('OC_Image->loadFromFile, JPG images not supported: ' . $imagePath, array('app' => 'core'));
}
break;
case IMAGETYPE_PNG:
@ -479,27 +489,21 @@ class OC_Image {
imagealphablending($this->resource, true);
imagesavealpha($this->resource, true);
} else {
OC_Log::write('core',
'OC_Image->loadFromFile, PNG images not supported: '.$imagePath,
OC_Log::DEBUG);
$this->logger->debug('OC_Image->loadFromFile, PNG images not supported: ' . $imagePath, array('app' => 'core'));
}
break;
case IMAGETYPE_XBM:
if (imagetypes() & IMG_XPM) {
$this->resource = imagecreatefromxbm($imagePath);
} else {
OC_Log::write('core',
'OC_Image->loadFromFile, XBM/XPM images not supported: '.$imagePath,
OC_Log::DEBUG);
$this->logger->debug('OC_Image->loadFromFile, XBM/XPM images not supported: ' . $imagePath, array('app' => 'core'));
}
break;
case IMAGETYPE_WBMP:
if (imagetypes() & IMG_WBMP) {
$this->resource = imagecreatefromwbmp($imagePath);
} else {
OC_Log::write('core',
'OC_Image->loadFromFile, WBMP images not supported: '.$imagePath,
OC_Log::DEBUG);
$this->logger->debug('OC_Image->loadFromFile, WBMP images not supported: ' . $imagePath, array('app' => 'core'));
}
break;
case IMAGETYPE_BMP:
@ -534,7 +538,7 @@ class OC_Image {
// this is mostly file created from encrypted file
$this->resource = imagecreatefromstring(\OC\Files\Filesystem::file_get_contents(\OC\Files\Filesystem::getLocalPath($imagePath)));
$iType = IMAGETYPE_PNG;
OC_Log::write('core', 'OC_Image->loadFromFile, Default', OC_Log::DEBUG);
$this->logger->debug('OC_Image->loadFromFile, Default', array('app' => 'core'));
break;
}
if ($this->valid()) {
@ -547,6 +551,7 @@ class OC_Image {
/**
* Loads an image from a string of data.
*
* @param string $str A string of image data as read from a file.
* @return bool|resource An image resource or false on error
*/
@ -564,7 +569,7 @@ class OC_Image {
}
if (!$this->resource) {
OC_Log::write('core', 'OC_Image->loadFromData, couldn\'t load', OC_Log::DEBUG);
$this->logger->debug('OC_Image->loadFromFile, could not load', array('app' => 'core'));
return false;
}
return $this->resource;
@ -572,6 +577,7 @@ class OC_Image {
/**
* Loads an image from a base64 encoded string.
*
* @param string $str A string base64 encoded string of image data.
* @return bool|resource An image resource or false on error
*/
@ -586,7 +592,7 @@ class OC_Image {
$this->mimeType = $this->fileInfo->buffer($data);
}
if (!$this->resource) {
OC_Log::write('core', 'OC_Image->loadFromBase64, couldn\'t load', OC_Log::DEBUG);
$this->logger->debug('OC_Image->loadFromBase64, could not load', array('app' => 'core'));
return false;
}
return $this->resource;
@ -597,6 +603,7 @@ class OC_Image {
/**
* Create a new image from file or URL
*
* @link http://www.programmierer-forum.de/function-imagecreatefrombmp-laeuft-mit-allen-bitraten-t143137.htm
* @version 1.00
* @param string $fileName <p>
@ -606,7 +613,7 @@ class OC_Image {
*/
private function imagecreatefrombmp($fileName) {
if (!($fh = fopen($fileName, 'rb'))) {
trigger_error('imagecreatefrombmp: Can not open ' . $fileName, E_USER_WARNING);
$this->logger->warning('imagecreatefrombmp: Can not open ' . $fileName, array('app' => 'core'));
return false;
}
// read file header
@ -614,7 +621,7 @@ class OC_Image {
// check for bitmap
if ($meta['type'] != 19778) {
fclose($fh);
trigger_error('imagecreatefrombmp: ' . $fileName . ' is not a bitmap!', E_USER_WARNING);
$this->logger->warning('imagecreatefrombmp: Can not open ' . $fileName . ' is not a bitmap!', array('app' => 'core'));
return false;
}
// read image header
@ -638,7 +645,7 @@ class OC_Image {
$meta['imagesize'] = @filesize($fileName) - $meta['offset'];
if ($meta['imagesize'] < 1) {
fclose($fh);
trigger_error('imagecreatefrombmp: Can not obtain filesize of ' . $fileName . '!', E_USER_WARNING);
$this->logger->warning('imagecreatefrombmp: Can not obtain file size of ' . $fileName . ' is not a bitmap!', array('app' => 'core'));
return false;
}
}
@ -658,6 +665,14 @@ class OC_Image {
}
// create gd image
$im = imagecreatetruecolor($meta['width'], $meta['height']);
if ($im == false) {
fclose($fh);
$this->logger->warning(
'imagecreatefrombmp: imagecreatetruecolor failed for file "' . $fileName . '" with dimensions ' . $meta['width'] . 'x' . $meta['height'],
array('app' => 'core'));
return false;
}
$data = fread($fh, $meta['imagesize']);
$p = 0;
$vide = chr(0);
@ -671,7 +686,7 @@ class OC_Image {
case 32:
case 24:
if (!($part = substr($data, $p, 3))) {
trigger_error($error, E_USER_WARNING);
$this->logger->warning($error, array('app' => 'core'));
return $im;
}
$color = unpack('V', $part . $vide);
@ -679,7 +694,7 @@ class OC_Image {
case 16:
if (!($part = substr($data, $p, 2))) {
fclose($fh);
trigger_error($error, E_USER_WARNING);
$this->logger->warning($error, array('app' => 'core'));
return $im;
}
$color = unpack('v', $part);
@ -726,9 +741,7 @@ class OC_Image {
break;
default:
fclose($fh);
trigger_error('imagecreatefrombmp: '
. $fileName . ' has ' . $meta['bits'] . ' bits and this is not supported!',
E_USER_WARNING);
$this->logger->warning('imagecreatefrombmp: ' . $fileName . ' has ' . $meta['bits'] . ' bits and this is not supported!', array('app' => 'core'));
return false;
}
imagesetpixel($im, $x, $y, $color[1]);
@ -744,12 +757,13 @@ class OC_Image {
/**
* Resizes the image preserving ratio.
*
* @param integer $maxSize The maximum size of either the width or height.
* @return bool
*/
public function resize($maxSize) {
if (!$this->valid()) {
OC_Log::write('core', __METHOD__.'(): No image loaded', OC_Log::ERROR);
$this->logger->error(__METHOD__ . '(): No image loaded', array('app' => 'core'));
return false;
}
$widthOrig = imageSX($this->resource);
@ -775,7 +789,7 @@ class OC_Image {
*/
public function preciseResize($width, $height) {
if (!$this->valid()) {
OC_Log::write('core', __METHOD__.'(): No image loaded', OC_Log::ERROR);
$this->logger->error(__METHOD__ . '(): No image loaded', array('app' => 'core'));
return false;
}
$widthOrig = imageSX($this->resource);
@ -783,7 +797,7 @@ class OC_Image {
$process = imagecreatetruecolor($width, $height);
if ($process == false) {
OC_Log::write('core', __METHOD__.'(): Error creating true color image', OC_Log::ERROR);
$this->logger->error(__METHOD__ . '(): Error creating true color image', array('app' => 'core'));
imagedestroy($process);
return false;
}
@ -797,7 +811,7 @@ class OC_Image {
imagecopyresampled($process, $this->resource, 0, 0, 0, 0, $width, $height, $widthOrig, $heightOrig);
if ($process == false) {
OC_Log::write('core', __METHOD__.'(): Error resampling process image '.$width.'x'.$height, OC_Log::ERROR);
$this->logger->error(__METHOD__ . '(): Error re-sampling process image', array('app' => 'core'));
imagedestroy($process);
return false;
}
@ -808,12 +822,13 @@ class OC_Image {
/**
* Crops the image to the middle square. If the image is already square it just returns.
*
* @param int $size maximum size for the result (optional)
* @return bool for success or failure
*/
public function centerCrop($size = 0) {
if (!$this->valid()) {
OC_Log::write('core', 'OC_Image->centerCrop, No image loaded', OC_Log::ERROR);
$this->logger->error('OC_Image->centerCrop, No image loaded', array('app' => 'core'));
return false;
}
$widthOrig = imageSX($this->resource);
@ -840,7 +855,7 @@ class OC_Image {
}
$process = imagecreatetruecolor($targetWidth, $targetHeight);
if ($process == false) {
OC_Log::write('core', 'OC_Image->centerCrop. Error creating true color image', OC_Log::ERROR);
$this->logger->error('OC_Image->centerCrop, Error creating true color image', array('app' => 'core'));
imagedestroy($process);
return false;
}
@ -854,9 +869,7 @@ class OC_Image {
imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $targetWidth, $targetHeight, $width, $height);
if ($process == false) {
OC_Log::write('core',
'OC_Image->centerCrop. Error resampling process image '.$width.'x'.$height,
OC_Log::ERROR);
$this->logger->error('OC_Image->centerCrop, Error re-sampling process image ' . $width . 'x' . $height, array('app' => 'core'));
imagedestroy($process);
return false;
}
@ -867,6 +880,7 @@ class OC_Image {
/**
* Crops the image from point $x$y with dimension $wx$h.
*
* @param int $x Horizontal position
* @param int $y Vertical position
* @param int $w Width
@ -875,12 +889,12 @@ class OC_Image {
*/
public function crop($x, $y, $w, $h) {
if (!$this->valid()) {
OC_Log::write('core', __METHOD__.'(): No image loaded', OC_Log::ERROR);
$this->logger->error(__METHOD__ . '(): No image loaded', array('app' => 'core'));
return false;
}
$process = imagecreatetruecolor($w, $h);
if ($process == false) {
OC_Log::write('core', __METHOD__.'(): Error creating true color image', OC_Log::ERROR);
$this->logger->error(__METHOD__ . '(): Error creating true color image', array('app' => 'core'));
imagedestroy($process);
return false;
}
@ -894,7 +908,7 @@ class OC_Image {
imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $w, $h, $w, $h);
if ($process == false) {
OC_Log::write('core', __METHOD__.'(): Error resampling process image '.$w.'x'.$h, OC_Log::ERROR);
$this->logger->error(__METHOD__ . '(): Error re-sampling process image ' . $w . 'x' . $h, array('app' => 'core'));
imagedestroy($process);
return false;
}
@ -904,14 +918,15 @@ class OC_Image {
}
/**
* Resizes the image to fit within a boundry while preserving ratio.
* Resizes the image to fit within a boundary while preserving ratio.
*
* @param integer $maxWidth
* @param integer $maxHeight
* @return bool
*/
public function fitIn($maxWidth, $maxHeight) {
if (!$this->valid()) {
OC_Log::write('core', __METHOD__.'(): No image loaded', OC_Log::ERROR);
$this->logger->error(__METHOD__ . '(): No image loaded', array('app' => 'core'));
return false;
}
$widthOrig = imageSX($this->resource);
@ -936,9 +951,11 @@ class OC_Image {
$this->destroy();
}
}
if (!function_exists('imagebmp')) {
/**
* Output a BMP image to either the browser or a file
*
* @link http://www.ugia.cn/wp-data/imagebmp.php
* @author legend <legendsky@hotmail.com>
* @link http://www.programmierer-forum.de/imagebmp-gute-funktion-gefunden-t143716.htm
@ -952,8 +969,7 @@ if ( ! function_exists( 'imagebmp') ) {
function imagebmp($im, $fileName = '', $bit = 24, $compression = 0) {
if (!in_array($bit, array(1, 4, 8, 16, 24, 32))) {
$bit = 24;
}
else if ($bit == 32) {
} else if ($bit == 32) {
$bit = 24;
}
$bits = pow(2, $bit);
@ -989,8 +1005,7 @@ if ( ! function_exists( 'imagebmp') ) {
}
$bmpData .= $extra;
}
}
// RLE8
} // RLE8
else if ($compression == 1 && $bit == 8) {
for ($j = $height - 1; $j >= 0; $j--) {
$lastIndex = "\0";
@ -1003,8 +1018,7 @@ if ( ! function_exists( 'imagebmp') ) {
}
$lastIndex = $index;
$sameNum = 1;
}
else {
} else {
$sameNum++;
}
}
@ -1014,8 +1028,7 @@ if ( ! function_exists( 'imagebmp') ) {
}
$sizeQuad = strlen($rgbQuad);
$sizeData = strlen($bmpData);
}
else {
} else {
$extra = '';
$padding = 4 - ($width * ($bit / 8)) % 4;
if ($padding % 4 != 0) {
@ -1032,8 +1045,7 @@ if ( ! function_exists( 'imagebmp') ) {
$bin |= ($colors['green'] >> 3) << 5;
$bin |= $colors['blue'] >> 3;
$bmpData .= pack("v", $bin);
}
else {
} else {
$bmpData .= pack("c*", $colors['blue'], $colors['green'], $colors['red']);
}
}
@ -1059,6 +1071,7 @@ if ( ! function_exists( 'imagebmp') ) {
if (!function_exists('exif_imagetype')) {
/**
* Workaround if exif_imagetype does not exist
*
* @link http://www.php.net/manual/en/function.exif-imagetype.php#80383
* @param string $fileName
* @return string|boolean