[nycphp-talk] PHPThumb -- how does it work??
David Krings
ramons at gmx.net
Fri Jan 4 07:01:09 EST 2008
Jonathan Wagener wrote:
> Hi, I would like to know how I can make phpthumb work, I don't really
> understand how it works. How do I make it create thumbnails?
>
Hi!
I can't answer your question, but I know about an alternative. You can use
exif to read out the thumbnail from jpegs and then display that. The thumbnail
is stored as a string, but PHP has functions for that. I put this together
with a lot of help from the smart people from NYPHP.
This is the piece of code that displays the thumbnail
// Show thumbnail
$exifthumbnail = exif_thumbnail($totalpath, $exifwidth, $exifheight,
$exiftype);
if ($exifthumbnail !== FALSE) {
echo "<tr><td>Thumbnail image</td><td><img class=\"centerborder\" ".
"src=\"tn.php?degrees=".$rotate."&f=".$totalpath."\">";
echo "</td></tr>\n";
} else {
echo "<tr><td>Thumbnail image</td><td>No thumbnail
available!</td></tr>\n";
}
And that is piece of code that makes the thumbnail (reference above as tn.php):
<?php
// =============================================================================
// This script is a helper script to generate a thumbnail image from Exif data
// =============================================================================
if ($_GET['degrees'] == 0) {
$image = exif_thumbnail($_GET['f'], $width, $height, $type);
header('Content-type: ' .image_type_to_mime_type($type));
echo $image;
} else {
$image = exif_thumbnail($_GET['f'], $width, $height, $type);
$realimage = imagecreatefromstring($image);
$rotimage = imagerotate($realimage, $_GET['degrees'], 0);
header('Content-type: ' .image_type_to_mime_type($type));
imagejpeg($rotimage);
// echo $rotimage;
}
?>
$totalpath is the path to the jped image, $degrees is the amount of degrees
the thumbnail needs to be rotated (the same as the image, I specify the angle
on image insert/edit, also some cameras have a sensor that stores it in the
exif info), the $exif.... values are straight from the thumbnail info out of
the exif header. I display all exif info in a table and show the thumbnail in
the table cell centered with a border (see class for img tag). The really
weird thing with this is that the img tag src value is a link to the tn.php
script. Also a nice example where GET comes to the rescue where POST would be
awfully complicated.
HTH,
David
More information about the talk
mailing list