I am trying to take a file by reference in a new-fashioned format and save it in a PNG format. Here is an example of the file that I take on the link.

Here is the code that works correctly with other files, and it gives an error with this file or other photos from the Googleme play directory.

// Load the WebP file $im = imagecreatefromwebp('http://sdev.ml/1.webp'); // Convert it to a jpeg file with 100% quality imagejpeg($im, 'example.jpeg', 100); imagedestroy($im); 

But I get the following errors:

  Warning: imagecreatefromwebp(): WebP decode: fail to decode input data in W:\domains\gpget.ru\index.php on line 107 Warning: imagecreatefromwebp(): 'http://sdev.ml/1.webp' is not a valid WEBP file in W:\domains\gpget.ru\index.php on line 107 Warning: imagejpeg() expects parameter 1 to be resource, boolean given in W:\domains\gpget.ru\index.php on line 110 Warning: imagedestroy() expects parameter 1 to be resource, boolean given in W:\domains\gpget.ru\index.php on line 111 
  • 3
    Check that the latest version of libwebp (0.5) and the latest version of libgd (2.2.2) are installed. - Arnial

1 answer 1

Yes, correctly noted in the comments about the version of libwebp, libgd, it is necessary to check their version and compatibility with your PHP.

This error indicates that the file is not valid.

In general, you can not trust the file extension looking in the url.

Pictures may not be webp a png

Read the mime file, and then through the switch the corresponding imagecreatefrom ... ()

 $finfo = new finfo(FILEINFO_MIME); echo $finfo->buffer('http://sdev.ml/1.webp'); 

In your case, mime = text / plain; charset = us-ascii

And had to be in my application / webp

  • Thanks for the tip, I will soon tick off your answer! However, maybe you know how to convert such files after all? I am already desperate - Seredniy
  • The fact is that this file does not even exist var_dump (file_exists (' sdev.ml/1.webp' )); I looked in the headers but for now I’m type application / xhtml + xml. A few minutes ago was different. - Vanya Avchyan pm
  • strange thing. I will look tomorrow, fill in a couple of test files and check again. You say the file would not, but the link is the same? full picture .... - Seredniy
  • one
    See the html to image php script buffernow.com/html-to-image-php-script , but these are all hacked options, then it converts html to pdf and then pdf to image. - Vanya Avchyan
  • There in my redirect 304 is in the headers. Here is the next thing I got when I tried Impossible to load the image sdev.ml/1.webp . the only thing you can do is find some kind of php lib html to image and pass it to him like this <img style = "- webkit-user-select: none" src = " sdev.ml/1.webp "> - Vanya Avchyan