imagecreatefromxbm 


gd apg

CREATE a new image from file or URL from a XBM image.





This function returns an image identifier representing the image obtained from the given filename.





This function returns FALSE on errors.

The GdImage, resource or object returned by this function allows the creation of other image formats from XBM format.



<?php

GdImage
|false imagecreatefromxbmstring $filename )


where,

$filename The path to an existing XBM image 

?>
 

  $filename   


The path or stream resource.

$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


  1 EXERCISE   

<?php

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

$var getcwd();
define('STWP''file://' $var '/');

echo 
'STWP = ' STWP '<br><br>';

$img_file "xbm/XBM 0029 10.xbm";

$img_name "png/PNG 023 01 (xbm-png).png";  

echo 
$img_file?><br><br>Existing Image...<br>
however, it cannot be displayed by this browser.

<?php

$im01 
imagecreatefromxbm(STWP $img_file); 
// VIA STREAM WRAPPER

echo '<br><br>The resource or object to be used 
          to create another image format:<br><br>'
;

var_dump($im01);

echo 
'<br>'

$bool01 imagepng($im01$img_name);   

if (
$bool01 == true)   
{   
echo 
'<br><br>The new format of the image 
          has been created!<br><br>' 
$img_name '<br><br>';  

echo 
'<img src="' $img_name 
'" alt="' $img_name '" title="' $img_name '">';  
}   
else   
{   
echo 
'$bool01 = ' $bool01 
  
'<br><br>The image was NOT created!';   
}   

?> 

 RESULT   

XBM 0029 10.xbm

Existing image, however, it cannot be displayed by this browser.



The .png format of the image has been created!


PNG 023 01 (xbm-png).png

PNG 023 01 (xbm-png).png apr

  2 EXERCISE   

<?php

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

$img_file "xbm/XBM 002 02.xbm";

$img_name "gif/GIF 012 02 (xbm-gif).gif";  

echo 
$img_file?><br><br>Existing Image...<br>
however, it cannot be displayed by this browser.

<?php

$im02 
imagecreatefromxbm($img_file); 

echo 
'<br><br>The resource or object to be used 
          to create another image format:<br><br>'
;

var_dump($im02);

echo 
'<br>'

$bool02 imagegif($im02$img_name);   

if (
$bool02 == true)   
{   
echo 
'<br><br>The new format of the image 
          has been created!<br><br>' 
$img_name '<br><br>';  

echo 
'<img src="' $img_name 
'" alt="' $img_name '" title="' $img_name '">';  
}   
else   
{   
echo 
'$bool02 = ' $bool02 
  
'<br><br>The image was NOT created!';   
}   

?> 

 RESULT   

XBM 002 02.xbm

Existing image, however, it cannot be displayed by this browser.



The .gif format of the image has been created!


GIF 012 02 (xbm-gif).gif

GIF 012 02 (xbm-gif).gif apr

  3 EXERCISE   

<?php

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

$img_file "xbm/XBM 003 05 (gif2xbm).xbm";

$img_name "jpeg/JPEG 015 03 (xbm-jpeg).jpg";  

echo 
$img_file?><br><br>Existing Image...<br>
however, it cannot be displayed by this browser.

<?php

$im03 
imagecreatefromxbm($img_file);

echo 
'<br><br>The resource or object to be used 
          to create another image format:<br><br>'
;

var_dump($im03);

echo 
'<br>'

$bool03 imagejpeg($im03$img_name);   

if (
$bool03 == true)   
{   
echo 
'<br><br>The new format of the image 
          has been created!<br><br>' 
$img_name '<br><br>';  

echo 
'<img src="' $img_name 
'" alt="' $img_name '" title="' $img_name '">';  
}   
else   
{   
echo 
'$bool03 = ' $bool03 
  
'<br><br>The image was NOT created!';   
}   

?> 

 RESULT   

XBM 003 05 (gif2xbm).xbm

Existing image...
however, it cannot be displayed by this browser.



The .jpg format of the image has been created!

JPEG 015 03 (xbm-jpeg).jpg

JPEG 015 03 (xbm-jpeg).jpg apr

This function requires the original image to be black and white, otherwise it will be displayed incorrectly, as shown above.

  4 EXERCISE   

<?php

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

$var getcwd();
define('STWP''file://' $var '/');

echo 
'STWP = ' STWP '<br><br>';

$img_file "xbm/XBM 004 04 P de Galinhas (bmp2xbm).xbm";

$img_name "jpeg/JPEG 016 04 P de Galinhas (xbm-jpeg).jpg";  

echo 
$img_file?><br><br>Existing Image...<br>
however, it cannot be displayed by this browser.

<?php

$im04 
imagecreatefromxbm(STWP $img_file);
// VIA STREAM WRAPPER 

echo '<br><br>'

echo 
'<br><br>The resource or object to be used 
          to create another image format:<br><br>'
;

var_dump($im04);

echo 
'<br>';

$bool04 imagejpeg($im04$img_name);   

if (
$bool04 == true)   
{   
echo 
'<br><br>The new format of the image 
          has been created!<br><br>' 
$img_name '<br><br>';  

echo 
'<img src="' $img_name 
'" alt="' $img_name '" title="' $img_name '" width="400">';  
}   
else   
{   
echo 
'$bool04 = ' $bool04 
  
'<br><br>The image was NOT created!';   
}   

?> 

 RESULT   

XBM 004 04 P de Galinhas (bmp2xbm).xbm

Existing image...
however, it cannot be displayed by this browser.



The .jpg format of the image has been created!

JPEG 016 04 P de Galinhas (xbm-jpeg).jpg

JPEG 016 04 P de Galinhas (xbm-jpeg).jpg apr

This image has only two colors, (white and black), so this function displays a correct result as shown.