# WebP Support in `imagecreatefromstring()`

> Section in “New and Extended Functionality › Graphics” of the book [PHP 7 Explained](https://php7explained.com/) by Sebastian Bergmann and Stefan Priebsch, published by thePHP.cc. The book covers PHP 7.0 to 7.4 and was last updated in November 2020. HTML version: <https://php7explained.com/new-and-extended-functionality/graphics/webp-support-in-imagecreatefromstring/>

[WebP](https://developers.google.com/speed/webp) is an image format that supports lossless as well as lossy compression. As of PHP 7.3, the `imagecreatefromstring()` function also supports the WebP format. This allows creating a new image resource that can be used with the other functions provided by the GD extension from a string that contains a WebP image stream:

``` php
// Load WebP image stream from file
$imageStream = file_get_contents(__DIR__ . '/image.webp');

// Create GD image resource from image stream
$image = imagecreatefromstring($imageStream);

// Do something with the image resource

// Clean up image resource
imagedestroy($image);
```

---

Previous: [New GD Functions](https://php7explained.com/new-and-extended-functionality/graphics/new-gd-functions/index.html.md) | Next: [Internationalisation and Unicode](https://php7explained.com/new-and-extended-functionality/internationalisation-and-unicode/index.html.md)
