PHP | imagebmp() Function

The imagebmp() function is an inbuilt function in PHP which is used to return the output or save a BMP version of the given image.

Syntax:

bool imagebmp( resource $image, mixed $to, bool $compressed )

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



  • $image: It specifies the image to be converted.
  • $to (Optional): It specifies the path to save file to.
  • $compressed (Optional): It specifies whether BMP should be compressed with run-length encoding or not.

Return Value: This function returns TRUE on success.

Exceptions: This function throws Exception on error.

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

Program 1 (Creating a bmp image from scratch):

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a blank image
$im = imagecreatetruecolor(120, 100);
  
// Add text in image
$text_color = imagecolorallocate($im, 200, 240, 21);
imagestring($im, 1, 5, 50,  'GeeksforGeeks', $text_color);
  
// Output that image as bmp
header("Content-Type: image/bmp");
imagebmp($im);
?>

chevron_right


Output:

Program 2 (Converting a image into bmp):

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a image from URL
$im = imagecreatefrompng(
  
// Output that image as bmp
header("Content-Type: image/bmp");
imagebmp($im);
?>

chevron_right


Output:

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

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.