$base_dir="/home/spatieba/public_html/hoenson/foto";
$picture_location = $base_dir."/".$_GET['picture'];
//echo $picture_location;
if(isset($_GET['max_width'])){
$size=$_GET['max_width'];
}
else{
$size=250; // size in pixel u want the picture to come out
}
$destination = $base_dir."/_thumb/".$size."/".$_GET['picture'].".thumb";
if(file_exists($destination) && filesize($destination)>0){
Header("Content-type: image/jpeg");
$handle = fopen ($destination, "rb");
$contents = fread ($handle, filesize ($destination));
fclose ($handle);
echo $contents;
}
else{
$file_array = split("/",$destination);
foreach ($file_array as $dir){
$dir_tmp .= $dir."/";
if($dir !== "." && $dir !== "foto" && $dir !== "_thumb" && !eregi(".jpg",$dir)){
if(!file_exists($dir_tmp)){
mkdir($dir_tmp,0755);
}
}
}
$handle = fopen($destination,"wb");
fclose($handle);
$im_size = GetImageSize ($picture_location);
$imageWidth = $im_size[0];
$imageHeight = $im_size[1];
// - or with GD 2+ -
// do all your color allocations here
//$font_color_black = ImageColorAllocate( $im, 0,0,0);
$im2 = ImageCreateFromJPEG($picture_location);
if($imageHeight > $size || $imageWidth > $size){ // Dan pas resizen
if ($imageWidth>=$imageHeight)
{
$width=$size;
$height = ($width/$imageWidth)*$imageHeight;
}
else
{
$height=$size;
$width = ($height/$imageHeight)*$imageWidth;
}
}
else{
$height = $imageHeight;
$width = $imageWidth;
}
$im = imageCreateTrueColor($width, $height);
//imageAntiAlias($im,true);
if($size > 2000){ // dus alleen maar als het om het 'origineel' gaat en niet om een thumbnail
// Plaatje het logo meegeven
ImageAlphaBlending($im2, true);
$logo = ImageCreateFromPNG('logo.png');
ImageColorAllocate($logo,0,0,0);
ImageColorTransparent($logo,$black);
$logoW = ImageSX($logo);
$logoH = ImageSY($logo);
ImageCopy($im2, $logo, 1, 1, 0, 0, $logoW, $logoH);
}
ImageCopyResampled($im,$im2, 0, 0, 0, 0, $width, $height, $imageWidth, $imageHeight);
Header("Content-type: image/jpeg");
Imagejpeg($im);
Imagejpeg($im,$destination,100);
ImageDestroy($im);
ImageDestroy ($im2);
}
?>