imagexbm 


gd apg

CREATE a particular XBM image to be shown in a browser or stored in a file.





This function creates a XBM file in $file from the $image which is created by imagecreate or imagecreatetruecolor, for example.


PALETTE IMAGE

is the designation term for images with a small number of colors.

For this type of image, a maximum of 256 colors are accepted.


TRUECOLOR IMAGE

is the designation term for images with a great number of colors.

For this type of image, a maximum of 16,777,216 colors are accepted.





This function prior to PHP 5.6.24 and PHP 7.0.9 doesn't apply any padding, so the image width should be a multiple of 8.

This restriction no longer applies.

The default foreground color is black.

All other colors are treated as background.

This function returns TRUE on success or FALSE on failure.

However, if libgd fails to output the image, this function returns TRUE.





The X Bitmap

In computer graphics, the X Window System used X BitMap (XBM), a plain text binary image format, for storing cursor and icon bitmaps used in the X GUI.

The XBM format is superseded by XPM, which first appeared for X11 in 1989.

XBM files differ markedly from most image files in that they take the form of C source files.

This means that they can be compiled directly into an application without any preprocessing steps, but it also makes them far larger than their raw pixel data.

The image data is encoded as a comma-separated list of byte values, each written in the C hexadecimal notation, '0x13' for example, so that multiple ASCII characters are used to express a single byte of image information.

XBM data consists of a series of static unsigned char arrays containing the monochrome pixel data.

When the format was in common use, an XBM typically appeared in headers (.h files) which featured one array per image stored in the header.

From Wikipedia, the free encyclopedia.



<?php

bool imagexbm
GdImage $image
                                   ?
str $filename
                                   ?
int $foreground_color null )

where,

$image The image identifier 

$filename 
The path or stream resource 
                   
SEE the below TABLE 
          
$foreground_color The foreground color 
                                 obtained from imagecolorallocate

?>
 

  $image   


The image identifier.



  $filename   


The path or stream resource.

If $filename was not set or NULL, the raw image stream will be outputted directly.

$filename can reference a local file or, (configuration permitting), a remote file using one of the supported stream wrappers:

STREAM WRAPPERS MEANING
file:// LOCAL File System
http:// URL HTTP
ftp:// URL FTP
php:// I/O streams
zlib:// Data Compression stream
data:// DATA (RFC-2397)
glob:// Find Filenames
phar:// PHP Archive
ssh2:// Secure Shell 2
rar:// RAR
ogg:// Audio
expect:// Interaction of stream processes
ed48


  $foreground_color   


The foreground color obtained from imagecolorallocate.

As off PHP 8.0.0 $foreground_color is nullable.



  1 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

$im01 imagecreate(240100);
// you must try too
// $im01 = imagecreatetruecolor(240, 100);

$foreground01 
imagecolorallocate($im01195226245);

$imgxbm01 'xbm/XBM 001 01.xbm';

$bool01 imagexbm($im01$imgxbm01);

if(
$bool01 == TRUE)
{
    
var_dump($bool01);
    
    echo 
'<br><br>The image has been created, 
                    but can not be displayed!<br>'
;
}
else
{
    echo 
'The image was not created!';
}

imagedestroy($im01);

?>  

 RESULT   

XBM 001 01.xbm

bool(true)

The image has been created, but can not be displayed!

  2 EXERCISE   

<?php

// Try this code

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

$im02 imagecreatetruecolor(240100);

$foreground02 imagecolorallocate($im02195226245);

$txtcolor02 imagecolorallocate($im02000);

$imgxbm02 NULL;

$bool02 imagexbm($im02$imgxbm02);

if(
$bool02 == TRUE)
{   
    echo 
'<br><br>';
    
    
var_dump($bool02);
    
    echo 
'<br><br>The image has been created, 
                    but can not be displayed!<br>'
;
}
else
{
    echo 
'The image was not created!';
}

imagedestroy($im02);

?>