Friday, November 14, 2025
HomeLanguagesPHP | imagexbm() Function

PHP | imagexbm() Function

The imagexbm() function is an inbuilt function in PHP which is used to display image to browser a file. The main use of this function is to view an image in the browser and convert any other image type to XBM.

Syntax:

bool imagexbm( resource $image, int $to, int $foreground)

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

  • $image: It specifies the image resource to work on.
  • $to (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 imagexbm() function in PHP:

Example 1: In this example we will be downloading an image in browser.




<?php
  
// Load an xbm image from local folder
// Image can be converted into xbm using
// online convertors or imagexbm()
$im = imagecreatefromxbm('neveropen.xbm');
  
// Download the image
header('Content-Type: image/xbm');
imagexbm($im);
imagedestroy($im);
?>


Output:

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

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




<?php
  
// Load an image from PNG URL
$im = imagecreatefrompng(
  
// Convert the image into XBM using imagexbm() function
imagexbm($im, 'converted.xbm');
imagedestroy($im);
?>


Output:

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

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

RELATED ARTICLES

Most Popular

Dominic
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6765 POSTS0 COMMENTS
Nicole Veronica
11917 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11984 POSTS0 COMMENTS
Shaida Kate Naidoo
6889 POSTS0 COMMENTS
Ted Musemwa
7142 POSTS0 COMMENTS
Thapelo Manthata
6837 POSTS0 COMMENTS
Umr Jansen
6840 POSTS0 COMMENTS