Compare commits

..

No commits in common. '4f320e158fc902dedffbb8b5f7ac254944b20068' and '7fc3f8ef9f4730c145736ed4ced6fa57b04f93dc' have entirely different histories.

@ -666,59 +666,34 @@ class OC_Image implements \OCP\IImage {
* Get the correct file type from a buffered image
*
* @param string $buffer The image data to analyze
* @return bool
* @return void
*/
private function updateImageTypes($buffer) {
if ($this->valid()) {
if ($this->fileInfo) {
$this->mimeType = $this->fileInfo->buffer($buffer);
switch ($this->mimeType) {
case 'image/gif':
$this->imageType = IMAGETYPE_GIF;
break;
case 'image/jpeg':
$this->imageType = IMAGETYPE_JPEG;
break;
case 'image/png':
$this->imageType = IMAGETYPE_PNG;
break;
case 'image/xbm':
$this->imageType = IMAGETYPE_XBM;
break;
case 'image/vnd.wap.wbmp':
$this->imageType = IMAGETYPE_WBMP;
break;
case 'image/bmp':
$this->imageType = IMAGETYPE_BMP;
break;
case 'image/webp':
$this->imageType = IMAGETYPE_WEBP;
break;
default:
return false;
}
return true;
} else {
// Fallback: Use temporary file
$this->logger->debug('OC_Image->updateImageTypes, finfo not set, using temporary file as a fallback', ['app' => 'core']);
$tmpFile = tmpfile();
$tmpFileName = stream_get_meta_data($tmpFile)['uri'];
fwrite($tmpFile, $buffer);
fflush($tmpFile);
if (filesize($tmpFileName) < 12) {
return false;
}
$this->imageType = exif_imagetype($tmpFileName);
$this->mimeType = image_type_to_mime_type($this->imageType);
fclose($tmpFile);
return true;
$finfo = new finfo(FILEINFO_MIME_TYPE);
$this->mimeType = $finfo->buffer($buffer);
switch ($this->mimeType) {
case 'image/gif':
$this->imageType = IMAGETYPE_GIF;
break;
case 'image/jpeg':
$this->imageType = IMAGETYPE_JPEG;
break;
case 'image/png':
$this->imageType = IMAGETYPE_PNG;
break;
case 'image/xbm':
$this->imageType = IMAGETYPE_XBM;
break;
case 'image/vnd.wap.wbmp':
$this->imageType = IMAGETYPE_WBMP;
break;
case 'image/bmp':
$this->imageType = IMAGETYPE_BMP;
break;
case 'image/webp':
$this->imageType = IMAGETYPE_WEBP;
break;
}
}
}
@ -738,9 +713,7 @@ class OC_Image implements \OCP\IImage {
imagealphablending($this->resource, false);
imagesavealpha($this->resource, true);
}
if (!$this->updateImageTypes($str)) {
return false;
}
$this->updateImageTypes($str);
if (!$this->resource) {
$this->logger->debug('OC_Image->loadFromFile, could not load', ['app' => 'core']);
@ -762,9 +735,7 @@ class OC_Image implements \OCP\IImage {
$data = base64_decode($str);
if ($data) { // try to load from string data
$this->resource = @imagecreatefromstring($data);
if ($this->updateImageTypes($data)) {
return false;
}
$this->updateImageTypes($data);
if (!$this->resource) {
$this->logger->debug('OC_Image->loadFromBase64, could not load', ['app' => 'core']);
return false;

Loading…
Cancel
Save