0) { if(!is_dir($cache_dir)) mkdir($cache_dir,0777,true); $cachefile=$cache_dir.str_replace("..",".",$filename)."!".$width."!".$height."!".$crop."!".$bw.".jpg"; if(file_exists($cachefile)&&((time()-filectime($cachefile))<($cache_timeout+0))) { $file=$cachefile; $height=$width=0; unset($cachefile); } } // ======================= otevreni souboru ============================= if(($width+$height)==0) { header ("Content-type: image/jpeg"); readfile($file); exit; } if(!@$img = imagecreatefromjpeg($file)) { header("HTTP/1.0 504 Could not open"); die(); } $twidth=imagesx($img); $theight=imagesy($img); // ==== optimalizace velikosti souboru -------- if($max_width==0) $max_width=$twidth; if($max_height==0) $max_height=$theight; if($twidth>$max_width) { $tmax_height=min($max_height,$theight/$twidth*$max_width); $tmax_width=$twidth/$theight*$tmax_height; } elseif($theight>$max_height) { $tmax_width=min($max_width,$twidth/$theight*$max_height); $tmax_height=$theight/$twidth*$tmax_width; } if(isset($tmax_width)) { $max_img=imagecreatetruecolor($tmax_width,$tmax_height); imagecopyresampled($max_img,$img,0,0,0,0,$tmax_width,$tmax_height,$twidth,$theight); $twidth=$tmax_width; $theight=$tmax_height; @imagejpeg($max_img, $file, $max_quality); imagedestroy($img); $img=$max_img; } //=========================== velikost ========================================== if($ratio>0) { $height=$ratio*$theight; $width=$ratio*$twidth; } elseif(($crop==1)&&(($width>0)||($height>0))) { if($width==0) $width=$height=$height; elseif($height==0) $width=$height=$width; } if($width==0) $width =$twidth/$theight*$height; if($height==0) $height=$theight/$twidth*$width; //=========================== posun ========================================== $ttop=$tleft=0; if($crop==1) { if(($width/$height) < ($twidth/$theight)) $tleft=($twidth-($width/$height*$theight))/2; elseif(($width/$height) > ($twidth/$theight)) $ttop=($theight-($height/$width*$twidth))/2; } //=========================== vytvoreni obrazu ========================================== $timg=imagecreatetruecolor($width,$height); imagecopyresampled($timg,$img,0,0,$tleft,$ttop,$width,$height,$twidth-2*$tleft,$theight-2*$ttop); //=========================== post efekty ========================================== if($bw==1) imagetograyscale($timg); //=========================== watermark ========================================== // $signimg = imagecreatefrompng("nanokatka_watermark.png"); $twidth=imagesx($signimg); $theight=imagesy($signimg); // if($width>$height) { $ttheight=$height; $ttwidth=$ttheight*($twidth/$theight); } else { $ttwidth=$width; $ttheight=$ttwidth*($theight/$twidth); } // imagecopyresampled($timg,$signimg,($width-$ttwidth)/2,($height-$ttheight)/2,0,0,$ttwidth,$ttheight,$twidth,$theight); // imagettftext ($timg, 11.0, 45,imagesx($timg)-100, imagesy($timg)-20, // imagecolorallocatealpha($timg, 0, 0, 0, 0),"./verdana.ttf", "nanokatka.nipax.cz"); // ======================= cache writeout ============================= if(isset($cachefile)) { if(file_exists($cachefile)) @unlink($cachefile); else @mkdir(dirname($cachefile),0777,true); @imagejpeg($timg, $cachefile, $max_quality); } // ======================= VYSTUP ===================================== header ("Content-type: image/jpeg"); imagejpeg($timg, "", $max_quality); imagedestroy ($timg); ?>