Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

imagecreatefromwebp() -> imagejpeg() results in blue channel missing

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?

Original Image

enter image description here

Code

$pic = imagecreatefromwebp('https://lh4.ggpht.com/uaLB-tbci94IubJJhDZ4n6vJwGF4i9MpFLXl28LBHjVzLIy-K6fhoSILbM4yJcKqq9I=h900-rw');
imagejpeg($pic, './example.jpg', 80);
imagedestroy($pic);

Resulting Image

pic here http://savepic.ru/7812459.png

like image 590
emtecif Avatar asked Sep 20 '15 19:09

emtecif


People also ask

How to remove blue channel from color image in OpenCV Python?

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.

What is the use of imagecreatefromwebp ()?

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.

Can I use imagejpeg() before touch() in PHP?

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...

Can you run two imagejpeg() and imagegif() on the same resource?

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.


1 Answers

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

like image 164
timclutton Avatar answered Oct 29 '22 00:10

timclutton