exif_thumbnail 


EXIF apg

RETRIEVE the embedded thumbnail of an image.




This function returns the embedded thumbnail, or FALSE if the image contains no thumbnail.

If the $file is used to pass a stream to this function, then the stream must be seekable.

Note that the file pointer position is not changed after this function returns.


<?php

string
|false exif_thumbnail( resource|string $file,
                                                             
int &$width = null,
                                                             
int &$height = null,
                                                             
int &$image_type = null )

where,

$file = The location of the image file

$width 
= The thumbnail width to be returned
                 
$height 
= The thumbnail height to be returned

$image_type 
= The image type of the returned thumbnail

?>

  $file   


The location of the image file.

This can either be a path to the file (stream wrappers are also supported as usual) or a stream resource.



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

  $width   


The thumbnail width to be returned.

Passed by reference.



  $height   


The thumbnail height to be returned.

Passed by reference.



  $image_type   


The thumbnail imagetype to be returned.

Passed by reference.

This is either TIFF or JPEG.



  1 EXERCISE   

<?php

$img_f 
= "img/E 01  MADRID.jpg";

echo 
basename($img_f)
 . 
'<br><br>[ Madrid (SPAIN) ]<br><br>';
echo 
'<img src="' . $img_f . '" alt="' . 
$img_f . '" title="' . $img_f . '" width="70%">
<br><br>'
;

$info_img = getimagesize($img_f);
echo 
'<pre>Width = '
 
. $info_img['0'] . 'px<br>';
echo 
'Height = ' . $info_img['1'] . 'px<br>';
echo 
'Image Type = ' . $info_img['2'] . '<br>';
echo 
'html => ' . $info_img['3'] . '<br>';
echo 
'bits = ' . $info_img['bits'] . '<br>';
echo 
'Mime = ' . $info_img['mime'] . 
'</pre><br>';

$thumb_embutida = exif_thumbnail($img_f);

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - -

   Verifies the existence, or not, of the thumbnail
   
   If yes, collect the indicative string,  
   convert it to base 64 and present it.
   
   If not, issue a warning

   - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

if($thumb_embutida)
{
$thumb_b64 = base64_encode($thumb_embutida);
?>
JPEG<br>
<img src='data:image/jpeg;base64, <?php echo $thumb_b64; ?>' alt="thumb_jpeg" title="image/jpeg"><br><br>
PNG<br>
<img src='data:image/png;base64, <?php echo $thumb_b64; ?>' alt="thumb_png" title="image/png"><br><br>
GIF<br>
<img src='data:image/gif;base64, <?php echo $thumb_b64; ?>' alt="thumb_gif" title="image/gif">
<?php
}
else
{
echo 
'The THUMBNAIL does not exists!<br><br><br>';
}

?> 

 RESULT   

E 01 MADRID.jpg

( Madrid (SPAIN) )

E 01  MADRID.jpg apr

Width = 2464px
Height = 1632px
Image Type = 2
html => width="2464" height="1632"
bits = 8
Mime = image/jpeg

JPEG

thumb_jpeg apr

PNG

thumb_png apr

GIF

thumb_gif apr

  2 EXERCISE   

<?php

define
("PATH2IMG", 'img/');

$img_file_ch = "E 02 LOURDES.jpg";
$thumb_ch_jpeg = "E 02 LOURDES thumbnail.jpg";
$thumb_ch_png = "E 02 LOURDES thumbnail.png";
$thumb_ch_gif = "E 02 LOURDES thumbnail.gif";

echo 
$img_file_ch
 
. '<br><br>[ Lourdes (FRANCE) ]<br><br>';
echo 
'<img src="' . PATH2IMG . $img_file_ch . '" alt="' . 
$img_file_ch . '" title="' . $img_file_ch . '" width="70%">
<br><br>'
;

$info_jpeg_ch = getimagesize(PATH2IMG . $img_file_ch);
echo 
'<pre>Width = '
 
. $info_jpeg_ch['0'] . 'px<br>';
echo 
'Height = ' . $info_jpeg_ch['1'] . 'px<br>';
echo 
'Image Type = ' . $info_jpeg_ch['2'] . '<br>';
echo 
'html => ' . $info_jpeg_ch['3'] . '<br>';
echo 
'bits = ' . $info_jpeg_ch['bits'] . '<br>';
echo 
'Mime = ' . $info_jpeg_ch['mime'] . 
'<br><br><br><br>';

$thumb = exif_thumbnail(PATH2IMG . $img_file_ch);
$thumb_img = imagecreatefromstring($thumb);

imagejpeg($thumb_img, PATH2IMG . $thumb_ch_jpeg, 98);
echo 
$thumb_ch_jpeg
 
. '<br><br><img src="' .  PATH2IMG . 
$thumb_ch_jpeg . '" alt="' . $thumb_ch_jpeg . 
'" title="' . $thumb_ch_jpeg .  '">
<br>'
;
$thumb_img_jpeg_info = getimagesize(PATH2IMG . 
$thumb_ch_jpeg);
echo 
'<pre>Width = '
 
. $thumb_img_jpeg_info['0'] . 'px<br>';
echo 
'Height = ' . $thumb_img_jpeg_info['1'] . 'px<br>';
echo 
'Image Type = ' . $thumb_img_jpeg_info['2'] . '<br>';
echo 
'html => ' . $thumb_img_jpeg_info['3'] . '<br>';
echo 
'bits = ' . $thumb_img_jpeg_info['bits'] . '<br>';
echo 
'Mime = ' . $thumb_img_jpeg_info['mime'] . 
'</pre><br><br><br><br>';


imagepng($thumb_img, PATH2IMG . $thumb_ch_png);
echo 
$thumb_ch_png
 
. '<br><br><img src="' . 
PATH2IMG . $thumb_ch_png . '" alt="' . $thumb_ch_png .  
'" title="' . $thumb_ch_png . '"><br>';
$thumb_img_png_info = getimagesize(PATH2IMG . 
$thumb_ch_png);
echo 
'<pre>Width = '
 
. $thumb_img_png_info['0'] . 'px<br>';
echo 
'Height = ' . $thumb_img_png_info['1'] . 'px<br>';
echo 
'Image Type = ' . $thumb_img_png_info['2'] . '<br>';
echo 
'html => ' . $thumb_img_png_info['3'] . '<br>';
echo 
'bits = ' . $thumb_img_png_info['bits'] . '<br>';
echo 
'Mime = ' . $thumb_img_png_info['mime'] . '</pre>
<br><br><br><br>'
;



imagegif($thumb_img, PATH2IMG . $thumb_ch_gif);
echo 
$thumb_ch_gif . 
'<br><br><img src="' . PATH2IMG . $thumb_ch_gif . 
'" alt="' . $thumb_ch_gif . '" title="' . 
$thumb_ch_gif . '"><br>';
$thumb_img_gif_info = getimagesize(PATH2IMG . 
$thumb_ch_gif);
echo 
'<pre>Width = '
 
. $thumb_img_gif_info['0'] . 'px<br>';
echo 
'Height = ' . $thumb_img_gif_info['1'] . 'px<br>';
echo 
'Image Type = ' . $thumb_img_gif_info['2'] . '<br>';
echo 
'html => ' . $thumb_img_gif_info['3'] . '<br>';
echo 
'bits = ' . $thumb_img_gif_info['bits'] . '<br>';
echo 
'Mime = ' . $thumb_img_gif_info['mime'] . '</pre>
<br>'
;

?> 

 RESULT   

E 02 LOURDES.jpg

( Lourdes (FRANCE) )

E 02 LOURDES.jpg apr

Width = 2464px
Height = 1632px
Image Type = 2
html => width="2464" height="1632"
bits = 8
Mime = image/jpeg


E 02 LOURDES thumbnail.jpg

E 02 LOURDES thumbnail.jpg apr
Width = 160px
Height = 120px
Image Type = 2
html => width="160" height="120"
bits = 8
Mime = image/jpeg


E 02 LOURDES thumbnail.png

E 02 LOURDES thumbnail.png apr
Width = 160px
Height = 120px
Image Type = 3
html => width="160" height="120"
bits = 8
Mime = image/png


E 02 LOURDES thumbnail.gif

E 02 LOURDES thumbnail.gif apr
Width = 160px
Height = 120px
Image Type = 1
html => width="160" height="120"
bits = 8
Mime = image/gif


  3 EXERCISE   

<?php

// Run this code tosee the result

$img = 'img/E 01  MADRID.jpg';

echo 
'<img src="' . $img . '" alt="' . 
$img . '" title="' . $img . '" width="70%">
<br><br>'
;

$fp = fopen($img, 'rb');

echo 
$fp;

// echo '<br><br>';

// echo exif_thumbnail($fp);

echo '<br><br>';

var_dump(strlen(exif_thumbnail($fp)));

fclose($fp);

?>

 RESULT   

EXISTING IMAGE

img/E 01 MADRID.jpg

E 01  MADRID.jpg apr