imagecreatefrombmp 


gd apg

CREATE a new image from file or URL from a BMP 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 BMP format.



<?php

GdImage
|false imagecreatefrombmp( string $filename )


where,

$filename = The path to an existing BMP 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>';

$img_file = "bmp/BMP 004 01 Katedrála Sv. Víta.bmp";

$img_name = "jpeg/JPEG 011 01 Katedrála Sv. Víta (bmp2jpeg).jpg"; 

echo 
$img_file; ?><br><br>Existing Image 
<br><br><img src="<?php echo $img_file; ?>" 
alt="<?php echo $img_file; ?>" title="B M P" width="400"> 

<?php

$imi01 
= imagecreatefrombmp($img_file); 

echo 
'<br><br>The identifier to be used:<br><br>';

var_dump($imi01);

echo 
'<br><br>'; 

$bool01 = imagejpeg($imi01, $img_name);

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

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

?> 

 RESULT   

BMP 004 01 Katedrála Sv. Víta.bmp

Existing Image

BMP 004 01 Katedrála Sv. Víta.bmp apr


The new format of the image has been created!

JPEG 011 01 Katedrála Sv. Víta (bmp2jpeg).jpg

JPEG 011 01 Katedrála Sv. Víta (bmp2jpeg).jpg apr

  2 EXERCISE   

<?php 

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

$img_file = "bmp/BMP 005 02 P de Galinhas.bmp";

$img_name = "webp/WEBP 005 02 P de Galinhas (bmp2webp).webp"; 

echo 
$img_file; ?><br><br>( Existing Image ) 
<br><br><img src="<?php echo $img_file; ?>" 
alt="<?php echo $img_file; ?>" title="B M P" width="400"> 

<?php

$imi02 
= imagecreatefrombmp($img_file); 

echo 
'<br><br>The resource to be used:<br><br>';

var_dump($imi02);

echo 
'<br><br>'; 

$bool02 = imagewebp($imi02, $img_name);   

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

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

?> 

 RESULT   

BMP 005 02 P de Galinhas.bmp

Existing Image

BMP 005 02 P de Galinhas.bmp apr


The new format of the image has been created!

WEBP 005 02 P de Galinhas (bmp2webp).webp

WEBP 005 02 P de Galinhas (bmp2webp).webp apr

  3 EXERCISE   

<?php 

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

$img_file =  "bmp/BMP 005 02 P de Galinhas.bmp";

$img_name = "wbmp/WBMP 004 03 P de Galinhas (bmp2wbmp).wbmp"; 

echo 
$img_file; ?><br><br>Existing Image 
<br><br><img src="<?php echo $img_file; ?>" 
alt="<?php echo $img_file; ?>" title="B M P" width="400"> 

<?php

$imi03 
= imagecreatefrombmp($img_file); 

echo 
'<br><br>The resource to be used:<br><br>';

var_dump($imi03);

echo 
'<br><br>'; 

$bool03 = imagewbmp($imi03, $img_name);   

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

echo 
'Not displayed by this browser';
}   
else   
{   
echo 
'$bool03 = ' . $bool03 . 
         
'<br><br>The image was NOT created!';   
}   

?> 

 RESULT   

BMP 005 02 P de Galinhas.bmp

Existing Image

BMP 005 02 P de Galinhas.bmp apr


The .wbmp format of the image has been created!

WBMP 004 03 P de Galinhas (bmp2wbmp).wbmp

Not displayed by this browser.

  4 EXERCISE   

<?php

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

$img_file =  "bmp/BMP 007 03 P de Galinhas (wbmp2bmp).bmp";

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

echo 
$img_file; ?><br><br>Existing Image 
<br><br><img src="<?php echo $img_file; ?>" 
alt="<?php echo $img_file; ?>" title="B M P" width="400"> 

<?php

$imi04 
= imagecreatefrombmp($img_file); 

echo 
'<br><br>The resource to be used:<br><br>';

var_dump($imi04);

echo 
'<br><br>'; 

$bool04 = imagexbm($imi04, $img_name);   

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

echo 
'Not displayed by this browser';
}   
else   
{   
echo 
'$bool04 = ' . $bool04 . 
         
'<br><br>The image was NOT created!';   
}   

?> 

 RESULT   

BMP 007 03 P de Galinhas (wbmp2bmp).bmp

Existing Image

BMP 007 03 P de Galinhas (wbmp2bmp).bmp apr


The .xbm format of the image has been created!

XBM 004 04 P de Galinhas (bmp2xbm).xbm

Not displayed by this browser.