imagecreatefromjpeg 


gd apg

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



<?php

GdImage
|false imagecreatefromjpeg string $filename )


where,

$filename The path to an existing JPEG 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 "jpeg/JPEG 004 05.jpg";

$img_name "bmp/BMP 003 01 (jpeg2bmp).bmp"

echo 
$img_file?><br><br>Existing Image 
<br><br><img src="<?php echo $img_file?>
alt="<?php echo $img_file?>" title="J P E G" width="400"> 

<?php

$im01 
imagecreatefromjpeg($img_file); 

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

var_dump($im01);

echo 
'<br><br>'

$bool01 imagebmp($im01$img_name);

if (
$bool01 == 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 
'$bool01 = ' $bool01 
'<br><br>The image was NOT created!';   
}   

?> 

 RESULT   

JPEG 004 05.jpg

Existing Image

JPEG 004 05.jpg apr



BMP 003 01 (jpeg2bmp).bmp

New Image

BMP 003 01 (jpeg2bmp).bmp apr

  2 EXERCISE   

<?php

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

$img_file "jpeg/JPEG 009 02 (png2jpeg).jpg";

$img_name "gd2/GD2 005 02 (jpeg2gd2).gd2";

echo 
$img_file?><br><br>Existing Image
<br><br><img src="<?php echo $img_file?>
alt="<?php echo $img_file?>" title="J P E G">

<?php

$im02 
imagecreatefromjpeg($img_file);

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

var_dump($im02);

echo 
'<br><br>';

$bool02 imagegd2($im02$img_name);  

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

echo 
'However, it cannot be displayed by this browser.';  
}  
else  
{  
echo 
'$bool02 = ' $bool02 
          
'<br><br>The image was NOT created!';  
}  

?> 

 RESULT   

JPEG 009 02 (png2jpeg).jpg

Existing Image

JPEG 009 02 (png2jpeg).jpg apr

GD2 005 02 (jpeg2gd2).gd2

The new format of the image has been created!

However, it cannot be displayed by this browser.



  3 EXERCISE   

<?php

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

$img_file "jpeg/JPEG 010 03.jpg";

$img_name "wbmp/WBMP 003 03 (jpeg2wbmp).wbmp";

echo 
$img_file?><br><br>Existing Image
<br><br><img src="<?php echo $img_file?>
alt="<?php echo $img_file?>" title="J P E G">

<?php

$im03 
imagecreatefromjpeg($img_file);

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

var_dump($im03);

echo 
'<br><br>';

$bool03 imagewbmp($im03$img_name);  

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

echo 
'However, it cannot be displayed by this browser.';  
}  
else  
{  
echo 
'$bool03 = ' $bool03 
          
'<br><br>The image was NOT created!';  
}  

?> 

 RESULT   

JPEG 010 03.jpg

Existing Image

JPEG 010 03.jpg apr

WBMP 003 03 (jpeg2wbmp).wbmp

The new format of the image has been created!

However, it cannot be displayed by this browser.