note 124728 added to function.imagecreatefromwebp
| From: | Adam@php.net | Date: | Mon, 17 Feb 2020 12:06:28 +0000 |
| Subject: | note 124728 added to function.imagecreatefromwebp | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-214161@lists.php.net to get a copy of this message | ||
It seems that imagecreatefromwebp() function sometimes shifts the colors. I wanted to convert webp
image to jpeg format, but the converted image has lost its blue channel. I found a code, that helped
to fix the bug.
<?php
// Gets the webp image
$webp_image = imagecreatefromwebp('./source-image.webp');
// Creates a new tmp true color image
$width = imagesx($webp_image);
$height = imagesy($webp_image);
$image = imagecreatetruecolor($width, $height);
$c = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $c);
// Fixes blue channel
for($x=0; $x < $width; $x++) {
for($y=0; $y < $height; $y++) {
$rgb = imagecolorat($webp_image, $x, $y);
$r = ($rgb >> 24) & 0xFF;
$g = ($rgb >> 16) & 0xFF;
$b = ($rgb >> 8) & 0xFF;
$pixelcolor = imagecolorallocate($image, $r, $g, $b);
imagesetpixel($image, $x, $y, $pixelcolor);
}
}
// Save jpeg image
imagejpeg($image, './converted-image.jpg');
imagedestroy($image);
imagedestroy($webp_image);
?>
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.195 (proxied: 79.121.42.239)
----
Manual Page -- http://php.net/manual/en/function.imagecreatefromwebp.php
Edit -- https://master.php.net/note/edit/124728
Del: integrated -- https://master.php.net/note/delete/124728/integrated
Del: useless -- https://master.php.net/note/delete/124728/useless
Del: bad code -- https://master.php.net/note/delete/124728/bad+code
Del: spam -- https://master.php.net/note/delete/124728/spam
Del: non-english -- https://master.php.net/note/delete/124728/non-english
Del: in docs -- https://master.php.net/note/delete/124728/in+docs
Del: other reasons-- https://master.php.net/note/delete/124728
Reject -- https://master.php.net/note/reject/124728
Search -- https://master.php.net/manage/user-notes.php