Thursday, July 4, 2024
HomeLanguagesPhpPHP | imagecreatefromwebp() function

PHP | imagecreatefromwebp() function

The imagecreatefromwebp() function is an inbuilt function in PHP which is used to create a new image from WEBP file or URL. WEBP is an image format employing both lossy and lossless compression. This image can be further worked upon in the program. This function is usually used when you want to edit your images after loading them from a WEBP file. An image can be converted into WEBP using imagewebp() function.

Syntax:

resource imagecreatefromwebp( string $filename )

Parameters:This function accepts a single parameter $filename which holds the name of image.

Return Value: This function returns an image resource identifier on success, FALSE on errors.

Below given programs illustrate the imagecreatefromwebp() function in PHP:

Program 1:




<?php
// Load an WEBP image from local folder
// You can convert any image to WEBP using
// imagewebp() function or online convertors
$im = imagecreatefromwebp('./neveropen.webp');
  
// View the loaded image in browser
imagewebp($im);
imagedestroy($im);
?>


Output:

This will load the content into browser in the form of unsupported text as browsers don’t support WEBP.

Program 2:




<?php
// Load an WEBP image from local folder
// You can convert any image to WEBP using
// imagewebp() function or online convertors
$im = imagecreatefromwebp('./neveropen.webp');
  
// Output the image by converting it into PNG
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>


Output:

Reference: https://www.php.net/manual/en/function.imagecreatefromwebp.php

Nicole Veronica Rubhabha
Nicole Veronica Rubhabha
A highly competent and organized individual DotNet developer with a track record of architecting and developing web client-server applications. Recognized as a personable, dedicated performer who demonstrates innovation, communication, and teamwork to ensure quality and timely project completion. Expertise in C#, ASP.Net, MVC, LINQ, EF 6, Web Services, SQL Server, MySql, Web development,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments