|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-07-21 13:41 UTC] sramage at fatpipeinternet dot com
This error occurs almost every time, once every 20 times it actually works but most times it hangs.
Some times It actually finishes writing the file than it doesn't hang, it just autopmatically comes up with the standard
-- Cannot find server or DNS Error --
there is no problem with the DNS it just gives that error when it actually completes the file write.
if it does not complete the file write the file size of the created image == 0 and the browser goes into a constant loading cycle, but never loads the page.
Stats
Apache 1.3.22
GD Version 2.0 or higher
JPEG, PNG enabled
The following function is usually called within a class, if that matters.
it's not a bad piece of thumbnail code, feel free to use it at will.
Thanks
Steve
function CreateThumbnail($input_image,$fixed=true,$width=75,$height=75,$output_image=false){
//echo "$input_image<BR>$output_image <BR><BR>";
if(file_exists($input_image)){
// No Output File? Lets Improvise...
if(!$output_image){
$ext=strrev(strtok(strrev($input_image),"."));
$core=strrev(strtok(""));
$output_image=$core."_thumb.".$ext;
}
// Snag Image Size
if($dimensions = @GetImageSize($input_image)){
if($dimensions[2]==3 || $dimensions[2]==2){
// Set Height to Width Ratio.
$ratio = $dimensions[1] / $dimensions[0];
// Set up Thumbnail Dimensions
if($fixed){
$new_height = $height;
$new_width = $width;
$x = 0;
$y = 0;
}else{
if ($ratio * $width < $height) {
// if Height is greater than Width
$new_height = $ratio * $width;
$new_width = $width;
$x = 0;
$y = ($height - $new_height) / 2;
}else if ((1 / $ratio) * $height < $width) {
// if Width is greater than Height
$new_width = (1 / $ratio) * $height;
$new_height = $height;
$x = ($width - $new_width) / 2;
$y = 0;
}else {
// if Width is equal to Height
$new_width = $width;
$new_height = $height;
$x = 0;
$y = 0;
}
}
// Load up original image
switch($dimensions[2]){
case '3':
$image = ImageCreateFromPNG($input_image);
break;
case '2':
$image = ImageCreateFromJPEG($input_image);
break;
default:
$image=false;
break;
}
if($image){
// Create thumbnail in memory
$thumb = @ImageCreateTrueColor($width, $height);
$bg = @ImageColorAllocate($thumb, 255, 255, 255);
@ImageFill($thumb, 0, 0, $bg);
// Paste a resized original within the thumb borders
@ImageCopyResampled ($thumb, $image, $x, $y, 0, 0, $new_width, $new_height, @ImageSX($image), @ImageSY($image));
// Write Completed Thumbnail to Disk
if($dimensions[2]==3){
$return=@ImagePNG($thumb, "$output_image");
}else{
$return=@ImageJpeg($thumb, "$output_image");
}
}
}else{
$return=false;
//$this->error="cannot create thumbnail from specified image type";
}
}else{
$return=false;
}
}else{
$return=false;
}
return $return;
}//end function
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 04:00:01 2025 UTC |
//Sorry 'bout that, Brain Freeze =) function CreateThumbnail($input_image,$output_image){ $image = ImageCreateFromPNG($input_image); $thumb = ImageCreateTrueColor(75, 75); $bg = ImageColorAllocate($thumb, 255, 255, 255); ImageFill($thumb, 0, 0, $bg); ImageCopyResampled ($thumb, $image, 0, 0, 0, 0, 75,75, ImageSX($image), ImageSY($image)); return ImagePNG($thumb, "$output_image"); }//end function CreateThumbnail("original.png","thumb.png");