I am losing color information, seemingly the blue channel, from an image after using GD to read from the WebP version and output a JPEG. Why does this happen and how can I fix it?
$pic = imagecreatefromwebp('https://lh4.ggpht.com/uaLB-tbci94IubJJhDZ4n6vJwGF4i9MpFLXl28LBHjVzLIy-K6fhoSILbM4yJcKqq9I=h900-rw');
imagejpeg($pic, './example.jpg', 80);
imagedestroy($pic);
pic here http://savepic.ru/7812459.png
To remove blue channel from color image, read image to BGR array using cv2.imread () and assign zeros to the 2D array corresponding to blue channel. In this tutorial, we shall use OpenCV Python library and transform an image, such that no red channel is present in the image.
imagecreatefromwebp () returns an image identifier representing the image obtained from the given filename. Note that animated WebP files cannot be read. A URL can be used as a filename with this function if the fopen wrappers have been enabled.
According to the PHP staffer who has responded the docs are wrong (I don't agree but I'm also not their employee). The work around is to use touch () (or any other file system function that can do this) to create the file first before using imagejpeg (). A word of warning when outputting images to the browser...
By this I mean that you can not run two imagejpeg (), imagepng () or imagegif () calls on the same resource. Another possibly undocumented quirk... :- ( When displaying an image using imagepng or imagejpeg, you may want/need to call "header ("Content-type: image/jpeg")" before the imagepng and imagejpeg functions.
This looks like PHP bug #70102, "imagecreatefromwebm() shifts colors".
It is fixed in PHP >= 5.6.12 (release notes).
Your script works correctly for me (there is no yellow tint) in PHP 5.6.13
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With