private $width;
private $height;
private $valid;
- private $imageType;
+ private $outputType;
+ private $originType;
private $filename;
/**
$type = Images::addMimeTypeByExtensionIfInvalid($type, $filename);
if (Images::isSupportedMimeType($type)) {
- $this->imageType = Images::getImageTypeByMimeType($type);
+ $this->originType = $this->outputType = Images::getImageTypeByMimeType($type);
} elseif (($type == '') || substr($type, 0, 6) == 'image/' || substr($type, 0, 12) == ' application/') {
- $this->imageType = IMAGETYPE_WEBP;
+ $this->originType = IMAGETYPE_UNKNOWN;
+ $this->outputType = IMAGETYPE_WEBP;
DI::logger()->debug('Unhandled image mime type, use WebP instead', ['type' => $type, 'filename' => $filename, 'size' => strlen($data)]);
} else {
DI::logger()->debug('Unhandled mime type', ['type' => $type, 'filename' => $filename, 'size' => strlen($data)]);
return false;
}
- if ($this->imageType == IMAGETYPE_GIF) {
+ if ($this->outputType == IMAGETYPE_PNG) {
+ return true;
+ }
+
+ if ($this->originType == IMAGETYPE_GIF) {
$count = preg_match_all("#\\x00\\x21\\xF9\\x04.{4}\\x00[\\x2C\\x21]#s", $data);
return ($count > 0);
}
- return (($this->imageType == IMAGETYPE_WEBP) && $this->isAnimatedWebP(substr($data, 0, 90)));
+ return (($this->originType == IMAGETYPE_WEBP) && $this->isAnimatedWebP(substr($data, 0, 90)));
}
/**
/*
* Setup the image to the format it will be saved to
*/
- $this->image->setFormat(Images::getImagickFormatByImageType($this->imageType));
+ $this->image->setFormat(Images::getImagickFormatByImageType($this->outputType));
// Always coalesce, if it is not a multi-frame image it won't hurt anyway
try {
return false;
}
- return image_type_to_mime_type($this->imageType);
+ return image_type_to_mime_type($this->outputType);
}
/**
return false;
}
- return $this->imageType;
+ return $this->outputType;
}
/**
return false;
}
- return Images::getExtensionByImageType($this->imageType);
+ return Images::getExtensionByImageType($this->outputType);
}
/**
imagealphablending($dest, false);
imagesavealpha($dest, true);
- if ($this->imageType == IMAGETYPE_PNG) {
+ if ($this->outputType == IMAGETYPE_PNG) {
imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
}
*/
public function toStatic()
{
- if ($this->imageType != IMAGETYPE_GIF) {
+ if ($this->outputType != IMAGETYPE_GIF) {
return;
}
if ($this->isImagick()) {
- $this->imageType = IMAGETYPE_PNG;
- $this->image->setFormat(Images::getImagickFormatByImageType($this->imageType));
+ $this->outputType = IMAGETYPE_PNG;
+ $this->image->setFormat(Images::getImagickFormatByImageType($this->outputType));
}
}
imagealphablending($dest, false);
imagesavealpha($dest, true);
- if ($this->imageType == IMAGETYPE_PNG) {
+ if ($this->outputType == IMAGETYPE_PNG) {
imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
}
imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $max, $max, $w, $h);
break;
case IMAGETYPE_WEBP:
- imagewebp($this->image, $stream, DI::config()->get('system', 'jpeg_quality'));
+ @imagewebp($this->image, $stream, DI::config()->get('system', 'jpeg_quality'));
break;
case IMAGETYPE_BMP: