|
|
exif_thumbnail (PHP 4 >= 4.2.0, PHP 5) exif_thumbnail -- Retrieve the embedded thumbnail of a TIFF or JPEG image Описаниеstring exif_thumbnail ( string filename [, int &width [, int &height [, int &imagetype]]] )
exif_thumbnail() reads the embedded thumbnail of a
TIFF or JPEG image.
If you want to deliver thumbnails through this function, you should send
the mimetype information using the header() function.
It is possible that exif_thumbnail() cannot create an
image but can determine its size. In this case, the return value is
FALSE but width and height
are set.
Список параметров
filename
The name of the image file being read. This image contains an
embedded thumbnail.
width
The return width of the returned thumbnail.
height
The returned height of the returned thumbnail.
imagetype
The returned image type of the returned thumbnail. This is either
TIFF or JPEG.
Возвращаемые значения
Returns the embedded thumbnail, or FALSE if the image contains no
thumbnail.
Примеры
Пример 1. exif_thumbnail() example |
<?php
if (array_key_exists('file', $_REQUEST)) {
$image = exif_thumbnail($_REQUEST['file'], $width, $height, $type);
} else {
$image = false;
}
if ($image!==false) {
header('Content-type: ' .image_type_to_mime_type($type));
echo $image;
exit;
} else {
echo 'No thumbnail available';
}
?>
|
|
Miguel Vitorino
08-Oct-2007 06:37
use this if you want to embed a thumbnail directly on the HTML page without writing it first to a file:
<?php
$image = exif_thumbnail($file, $width, $height, $type);
echo "<img width='$width' height='$height' src='data:image/gif;base64,".base64_encode($image)."'>";
?>
05-Jan-2007 06:23
If you want to convert from TIFF to JPG you can use ImageMagick if it is installed in your server.
<?php
$exec = 'convert /path/to/file.tiff /path/to/file.jpg 2>&1';
@exec($exec, $exec_output, $exec_retval);
print_r($exec_output)
?>
hanspeter dot debets at dendrite dot com
14-Jan-2005 06:35
Great that the thumbnail can be in TIFF format (f.i. Kodak cameras have embedded thumbnail in TIFF) BUT I have not been able to show TIFF as an embedded image in HTML (using the <IMG...> tag). There seems to be no function in PHP to change TIFF to, lets say, JPG. (imagecreatefromstring gives a 'unknown datatype' error for the TIFF stream. So below sample works great for JPEG embedded thumbnail, but not for TIFF embedded (but then, maybe I did something wrong?):
test_exif.php:
<HTML>
<HEAD>
<TITLE>Test EXIF Read </TITLE>
</HEAD>
<BODY>
<?php
$image='P0000614.JPG';
echo("<B>". $image. "</B>:<BR><BR>\n");
$exif = exif_read_data($image, 'ANY_TAG',true);
if (!$exif===false)
{
echo("Image contains headers<br><br>");
echo("<A href=showthumb.php?image=" . $image ."> <IMG border=0 src=showthumb.php?image=" . $image ."></A><BR><BR>");
foreach ($exif as $key => $section)
{
foreach ($section as $name => $val)
{
echo "$key.$name: $val<br>\n";
}
}
}
else
{
echo("Sorry, image <B>".$image . "</B> does not contain (readable) EXIF data.");
}
?>
</BODY>
</HTML>
showthumb.php:
<?php
$imgdat = exif_thumbnail($_REQUEST['image'],$width, $height, $type);
header('Content-type: ' . image_type_to_mime_type($type));
echo($imgdat);
?>
When clicking on the <A> opens the TIFF image in the program that windows assigned to this type, but the JPEG opens in the browser.
I am using PHP 4.3.6 on windows iis 4 (yeah, I know.....)
Eric
13-Jun-2004 07:05
This will allow you to manipulate the thumbnail image ($imgJpeg) using the various gd commands:
<?php
if (($imgJpeg = exif_thumbnail($strImagePath)) === false)
print "No Thumbnail!";
else
$imgJpeg = imageCreateFromString($imgJpeg);
?>
neothermic at ya[]o dot com ADD ho IN GAP
26-May-2004 10:01
You can use the EXIF thumbnail function to extract the thumnails for use in an image gallery. I've found this to be faster than using other GD functions to convert the image to a smaller one then save it.
Here is the code I use to generate thumbnails. Remember, this is more of a utility script, although its simple to modifiy it for use...
<?PHP
set_time_limit(0); function getmicrotime() {
$temparray=split(" ",microtime());
$returntime=$temparray[0]+$temparray[1];
return $returntime;
}
echo "<html>
<head><title>Processing...</title></head>
<body>";
$maindir = "." ; $mydir = opendir($maindir) ;
$starttime=getmicrotime();
$i = 0; while($fn = readdir($mydir)) {$startimagetime = getmicrotime();
$ext = strtolower(substr($fn,strlen($fn)-3)); if ($ext == "jpg") {
$i++; echo $fn ." is being processed....<br>";
flush(); $image = exif_thumbnail($fn, $width, $height, $type);
if ($image!==false) {
$handle = fopen ($fn.".thumb.jpg", 'a');
fwrite($handle, $image);
} else {
echo "No thumbnail available for file ".$fn."<br>";
}
}
}
closedir($mydir);
$endtime=getmicrotime();
echo "<br>All Images have been processed, script is finshed.<br>Total processing time: ";
print $endtime-$starttime;
echo "<br> Images processed: " .$i;
echo "</body>";
echo "</html>"
?>
Its a bit crude, I must admit, but it can easily be adapted to suit user.
NeoThermic
|