note 52239 added to function.imagecopyresized
| From: | development at lab-9 dot com | Date: | Mon, 25 Apr 2005 22:35:03 +0000 |
| Subject: | note 52239 added to function.imagecopyresized | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88536@lists.php.net to get a copy of this message | ||
If you read your Imagedata from a Database Blob and use the functions from above to resize the image
to a thumbnail improving a lot of traffic, you will have to make temporary copies of the files in
order that the functions can access them
Here a example:
// switch through imagetypes
$extension = "jpg";
if(mysql_result($query, 0, 'type') == "image/pjpeg")
{ $extension = "jpg"; } // overwrite
else if(mysql_result($query, 0, 'type') == "image/gif")
{ $extension = "gif"; } // overwrite
// get a temporary filename
// use microtime() to get a unique filename
// if you request more than one file f.e. by creating large numbers of thumbnails, the server could
be not fast enough to save all these different files and you get duplicated copies and resizepics()
will resize and output often the same content
$filename = microtime()."_temp.".$extension;
// open
$tempfile = fopen($filename, "w+");
// write
fwrite($tempfile, mysql_result($query, 0, 'image'));
// close
fclose($tempfile);
// resize and output the content
echo resizepics($filename, '100', '70');
// delete temporary file
unlink($filename);
NOTE: this script has to be put into a file which sends correct header informations to the browser,
otherwise you won't get more to see than a big red cross :-)
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresized.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52239
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52239&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52239&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52239&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52239&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52239&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52239&report=yes
Search -- http://master.php.net/manage/user-notes.php