Open In App

PHP | image2wbmp() function

Last Updated : 17 Mar, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The image2wbmp() function is an inbuilt function in PHP which is used to display image to browser or file. The main use of this function is to view an image in the browser and convert any other image type to WBMP.
Syntax: 
 

bool image2wbmp( resource $image, int $filename, int $foreground)

Parameters: This function accepts three parameters as mentioned above and described below: 
 

  • $image: It specifies the image resource to work on.
  • $filename (Optional): It specifies the path to save the file to.
  • $foreground (Optional): It specifies the foreground of the image.

Return Value: This function returns TRUE on success or FALSE on error.
Below examples illustrate the image2wbmp() function in PHP: 
Example 1: In this example we will be downloading an image in browser. 
 

php




<?php
// Load an wbmp image from local folder
// Image can be converted into wbmp using
// online convertors or imagewbmp()
$im = imagecreatefromwbmp('geeksforgeeks.wbmp');
 
// Download the image
header('Content-Type: image/vnd.wap.wbmp');
image2wbmp($im);
imagedestroy($im);
?>


Output: 
 

This will download your image as download, 
further you can rename this file to anything like 
geeksforgeeks.wbmp and use it.

Example 2: In this example we will convert PNG into WBMP. 
 

php




<?php
// Load an image from PNG URL
$im = imagecreatefrompng(
 
// Convert the image into WBMP using image2wbmp() function
image2wbmp($im, 'converted.wbmp');
echo 'Image converted to WBMP successfully.';
imagedestroy($im);
?>


Output: 
 

This will save the WBMP version of image 
in the same folder where your PHP script is.

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


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads