|
|
|
@ -662,6 +662,42 @@ class OC_Image implements \OCP\IImage {
|
|
|
|
|
return $this->resource;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the correct file type from a buffered image
|
|
|
|
|
*
|
|
|
|
|
* @param string $buffer The image data to analyze
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
private function updateImageTypes($buffer) {
|
|
|
|
|
if ($this->valid()) {
|
|
|
|
|
$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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Loads an image from a string of data.
|
|
|
|
|
*
|
|
|
|
@ -673,13 +709,11 @@ class OC_Image implements \OCP\IImage {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$this->resource = @imagecreatefromstring($str);
|
|
|
|
|
if ($this->fileInfo) {
|
|
|
|
|
$this->mimeType = $this->fileInfo->buffer($str);
|
|
|
|
|
}
|
|
|
|
|
if (is_resource($this->resource)) {
|
|
|
|
|
imagealphablending($this->resource, false);
|
|
|
|
|
imagesavealpha($this->resource, true);
|
|
|
|
|
}
|
|
|
|
|
$this->updateImageTypes($str);
|
|
|
|
|
|
|
|
|
|
if (!$this->resource) {
|
|
|
|
|
$this->logger->debug('OC_Image->loadFromFile, could not load', ['app' => 'core']);
|
|
|
|
@ -701,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->fileInfo) {
|
|
|
|
|
$this->mimeType = $this->fileInfo->buffer($data);
|
|
|
|
|
}
|
|
|
|
|
$this->updateImageTypes($data);
|
|
|
|
|
if (!$this->resource) {
|
|
|
|
|
$this->logger->debug('OC_Image->loadFromBase64, could not load', ['app' => 'core']);
|
|
|
|
|
return false;
|
|
|
|
|