Answer the question
In order to leave comments, you need to log in
Resize webp php7.2 gives black screen. What's wrong?
Good evening dear community!
When transferring a project from a dev environment (openserver 5.2.2, php7.2, apache) to a product server, there was a problem with image processing.
What I do:
1) I accept jpg
2) I convert it to webp using imagewebp (great image)
3) I resize the webp file to 800x200px
4) I save the modified file (at first 1/3 of the image in terrible quality, and after 10 seconds a black screen, although the file with the correct size is ~ 50kb) I
use the gumlet/php-image-resize library in the project. I noticed the following lines in it when saving:
public function save($filename, $image_type = null, $quality = null, $permissions = null)
{
$image_type = $image_type ?: $this->source_type;
$quality = is_numeric($quality) ? (int) abs($quality) : null;
switch ($image_type) {
case IMAGETYPE_GIF:
$dest_image = imagecreatetruecolor($this->getDestWidth(), $this->getDestHeight());
$background = imagecolorallocatealpha($dest_image, 255, 255, 255, 1);
imagecolortransparent($dest_image, $background);
imagefill($dest_image, 0, 0, $background);
imagesavealpha($dest_image, true);
break;
case IMAGETYPE_JPEG:
$dest_image = imagecreatetruecolor($this->getDestWidth(), $this->getDestHeight());
$background = imagecolorallocate($dest_image, 255, 255, 255);
imagefilledrectangle($dest_image, 0, 0, $this->getDestWidth(), $this->getDestHeight(), $background);
break;
case IMAGETYPE_WEBP:
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
throw new ImageResizeException('For WebP support PHP >= 5.5.0 is required');
}
$dest_image = imagecreatetruecolor($this->getDestWidth(), $this->getDestHeight());
$background = imagecolorallocate($dest_image, 255, 255, 255);
imagefilledrectangle($dest_image, 0, 0, $this->getDestWidth(), $this->getDestHeight(), $background);
break;
case IMAGETYPE_PNG:
if (!$this->quality_truecolor && !imageistruecolor($this->source_image)) {
$dest_image = imagecreate($this->getDestWidth(), $this->getDestHeight());
$background = imagecolorallocatealpha($dest_image, 255, 255, 255, 1);
imagecolortransparent($dest_image, $background);
imagefill($dest_image, 0, 0, $background);
} else {
$dest_image = imagecreatetruecolor($this->getDestWidth(), $this->getDestHeight());
}
imagealphablending($dest_image, false);
imagesavealpha($dest_image, true);
break;
}
imageinterlace($dest_image, $this->interlace);
imagecopyresampled(
$dest_image,
$this->source_image,
$this->dest_x,
$this->dest_y,
$this->source_x,
$this->source_y,
$this->getDestWidth(),
$this->getDestHeight(),
$this->source_w,
$this->source_h
);
$this->applyFilter($dest_image);
switch ($image_type) {
case IMAGETYPE_GIF:
imagegif($dest_image, $filename);
break;
case IMAGETYPE_JPEG:
if ($quality === null || $quality > 100) {
$quality = $this->quality_jpg;
}
imagejpeg($dest_image, $filename, $quality);
break;
case IMAGETYPE_WEBP:
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
throw new ImageResizeException('For WebP support PHP >= 5.5.0 is required');
}
if ($quality === null) {
$quality = $this->quality_webp;
}
imagewebp($dest_image, $filename, $quality);
break;
case IMAGETYPE_PNG:
if ($quality === null || $quality > 9) {
$quality = $this->quality_png;
}
imagepng($dest_image, $filename, $quality);
break;
}
if ($permissions) {
chmod($filename, $permissions);
}
imagedestroy($dest_image);
return $this;
}
Answer the question
In order to leave comments, you need to log in
imagealphablending: for true color images blendmode = true
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question