'gif', 'jpeg', 'png', 'swf', 'psd', 'bmp', 'tiff', 'tiff', 'jpc', 'jp2', 'jpf', 'jb2', 'swc', 'aiff', 'wbmp', 'xbm'); // We are expecting an integer. $type = (int)$type; if (!$type) { trigger_error( '...come up with an error here...', E_USER_NOTICE ); return null; } if ( !isset($e[$type]) ) { trigger_error( 'Type not recognized', E_USER_NOTICE ); return null; } return ($dot ? '.' : '') . $e[$type]; } } if(is_dir($path)){ $d=dir($path); $atLeastOne=false; while(false !== ($entry = $d->read())){ $checkType=@getimagesize($path."/".$entry); if($checkType){ $check=convert($width,$height,$path."/".$entry,$thumb_dir); $atLeastOne=$check||$atLeastOne; //echo $entry; } } if(!$atLeastOne){ echo "No images resized"; exit; } } else{ $check=convert($width,$height,$path,$thumb_dir); if(!$check){ echo "Image conversion failed"; exit; } } function convert($w,$h,$p,$t){ $size = getimagesize($p); if(!$size){ $file = fopen("photouploadlog", 'a'); fwrite($file,"Image appears to be invalid- file:$p time:".time()."\n"); return false; } $ext=image_type_to_extension($size[2]); $x=pathinfo($p); $thumbname=substr($p,0,0-strlen(strrchr($p,"."))).".jpg"; $x=pathinfo($thumbname); $thumbname=$t."/BFS-".$x['basename']; $uploaded; $upname=$p; if($ext==".jpg"||$ext==".jpeg") $uploaded=imagecreatefromjpeg($p); elseif($ext==".gif") $uploaded=imagecreatefromgif($p); elseif($ext==".png") $uploaded=imagecreatefrompng($p); else{ $file = fopen("photouploadlog", 'a'); fwrite($file,"Image extension appears to be invalid- file:$p time:".time()."\n"); return false; } if(!$uploaded){ $file = fopen("photouploadlog", 'a'); fwrite($file,"Source image appears to be invalid- file:$p time:".time()."\n"); return false; } $ratio=1.0; if($size[0]/$w>$size[1]/$h) $ratio=1/($size[0]/$w); else $ratio=1/($size[1]/$h); $width=floor($ratio*$size[0]); $height=floor($ratio*$size[1]); $dim=min($size[0],$size[1]); $thumb=imagecreatetruecolor($w,$h); $white=imagecolorallocate($thumb,255,255,255); imagefill($thumb,0,0,$white); imagecopyresampled($thumb,$uploaded,floor(($w-$width)/2),floor(($h-$height)/2),0,0,$width,$height,$size[0],$size[1]); if($ext==".jpg"||$ext==".jpeg"){ imagejpeg($thumb,$thumbname); } elseif($ext==".gif"){ imagegif($thumb,$thumbname); } elseif($ext==".png"){ imagepng($thumb,$thumbname); } imagedestroy($thumb); imagedestroy($uploaded); if(file_exists($thumbname)){ $file = fopen("photosuccesses", 'a'); fwrite($file,"thumb: $thumbname, width: ".$size[0].", height: ".$size[1].", ratio: $ratio, adjusted width: $width, adjusted height: $height\n"); return true; } else{ $file = fopen("photofailures", 'a'); fwrite($file,"thumb: $thumbname, width: ".$size[0].", height: ".$size[1].", ratio: $ratio, adjusted width: $width, adjusted height: $height\n"); return false; } } echo "good"; ?>