Friday, August 29, 2025
HomeLanguagesPHP | imagecreatefrombmp() Function

PHP | imagecreatefrombmp() Function

The imagecreatefrombmp() function is an inbuilt function in PHP which is used to create a new image from file or URL.

Syntax:

resource imagecreatefrombmp( string $filename )

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

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

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

Program 1: Viewing a bmp file in browser.




<?php
  
// Load the BMP image
$im = imagecreatefrombmp(
  
// Output the image to browser
header('Content-type: image/bmp');  
imagebmp($im);
imagedestroy($im);
?>


Output:

Program 2: This program converting the bitmap into png.




<?php
  
// Load the BMP image
$im = imagecreatefrombmp(
  
// Convert it to a PNG file, press Ctrl + S to save the new png image
header('Content-type: image/png');  
imagepng($im);
imagedestroy($im);
?>


Output:

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

RELATED ARTICLES

Most Popular

Dominic
32249 POSTS0 COMMENTS
Milvus
80 POSTS0 COMMENTS
Nango Kala
6617 POSTS0 COMMENTS
Nicole Veronica
11790 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11838 POSTS0 COMMENTS
Shaida Kate Naidoo
6731 POSTS0 COMMENTS
Ted Musemwa
7011 POSTS0 COMMENTS
Thapelo Manthata
6689 POSTS0 COMMENTS
Umr Jansen
6701 POSTS0 COMMENTS