I'm having some trouble creating a clean looking image transcode from webp to jpeg using PHP's GD library. As a point of reference Here is a jpeg version of the original using Google's demo here: https://developers.google.com/speed/webp/gallery (I'm including this from the jpeg since I don't seem to be able to upload webp to stackoverflow)
First I tried this basic routine:
$image = imagecreatefromwebp('4.webp');
imagejpeg($image, 'converted.jpg', 100);
This kinda works but the result has a yellow background like this:
I also tried using this bit of code for resizing images and drawing a white background first:
$image = imagecreatefromwebp('4.webp');
$width = imagesx($image);
$height = imagesy($image);
$new = imagecreatetruecolor($width, $height);
$background = imagecolorallocate($new, 255, 255, 255);
imagefilledrectangle($new, 0, 0, $width, $height, $background);
imagecopyresampled($new, $image, 0, 0, 0, 0, $width, $height, $width, $height);
imagejpeg($new, 'converted.jpg', 100);
This looks even worse and results in lots of strange artifacts:
Before I completely give up on GD can anyone make a suggestion to get this working properly? First and foremost, I'm looking for a solution using GD functions. If it's not possible I'm open to ImageMagick or another library - but I'd like a bit more insight into what's going wrong here and if it can be done correctly without changing tools.