код староват, еще с телефона писал, но работает до сих пор
<?php
if(isset($_GET['image'])){
$image = $_GET['image'];
$max_height='176';
$max_width='132';
$font_size = '11';
$top_size = '5';
}
if(isset($_GET['prev'])){
$image = $_GET['prev'];
$max_height='64';
$max_width='56';
$font_size = '5';
$top_size = '1';
}
$copy = 'SMARTOFF.NET'; // текст
$ttf = '../data/verdana.ttf'; // путь к шрифту от корня сайта
$red = '255'; $green = '25'; $blue = '35';
if(file_exists('files/'.$image) AND preg_match('|^[a-z0-9\-\_\.\(\)]+$|iu',$image)){ // путь к изображению
$extension=explode('.',$image);
$extension=$extension[count($extension)-1];
$extension = strtolower($extension);
$image = 'files/'.$image;
if($extension=="jpg"){
$imgsize = GetImageSize($image);
$width=$imgsize[0];
$height=$imgsize[1];
$x_ratio=$max_width/$width;
$y_ratio=$max_height/$height;
if($width<$max_width && $height<$max_height){
$tn_width=$width;
$tn_height=$height;
}
else if(($x_ratio*$height)<$max_height){
$tn_height=ceil($x_ratio*$height);
$tn_width=$max_width;
}else{
$tn_width=ceil($y_ratio*$width);
$tn_height=$max_height;
}
$src=ImageCreateFromJpeg($image);
$dst = ImageCreateTrueColor($tn_width, $tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
$color = ImageColorAllocate($dst, $red, $green, $blue);
ImageTTFtext($dst, $font_size, 0, $top_size, $tn_height-2, $color, $ttf, $copy);
header("Content-type: image/jpeg");
ImageJpeg($dst, null, 100);
ImageDestroy($src);
ImageDestroy($dst);
}
if($extension=="gif"){
$size=GetImageSize($image);
$width=$size[0];
$height=$size[1];
$x_ratio=$max_width/$width;
$y_ratio=$max_height/$height;
if($width<=$max_width && $height<=$max_height){
$tn_width=$width;
$tn_height=$height;
}else if(($x_ratio*$height)<$max_height){
$tn_height=ceil($x_ratio*$height);
$tn_width=$max_width;
}else{
$tn_width=ceil($y_ratio*$width);
$tn_height=$max_height;
}
$src=ImageCreateFromGif($image);
$dst=ImageCreateTrueColor($tn_width,$tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
$color = ImageColorAllocate($dst, $red, $green, $blue);
ImageTTFtext($dst, $font_size, 0, $top_size, $tn_height-2, $color, $ttf, $copy);
header("Content-type: image/gif");
ImageGif($dst);
ImageDestroy($src);
ImageDestroy($dst);
}
if($extension=="png"){
$size = GetImageSize($image);
$width=$size[0];
$height=$size[1];
$x_ratio=$max_width/$width;
$y_ratio=$max_height/$height;
if($width<=$max_width &&$height<=$max_height){
$tn_width=$width;
$tn_height=$height;
}else if(($x_ratio*$height)<$max_height){
$tn_height=ceil($x_ratio*$height);
$tn_width=$max_width;
}else{
$tn_width=ceil($y_ratio*$width);
$tn_height=$max_height;
}
$src = ImageCreateFromPng($image);
$dst=ImageCreateTrueColor($tn_width, $tn_height);
ImageCopyResized($dst,$src,0,0,0,0,$tn_width,$tn_height,$width,$height);
//ImageColorTransparent($dst,'0');
$color = ImageColorAllocate($dst, $red, $green, $blue);
ImageTTFtext($dst, $font_size, 0, $top_size, $tn_height-2, $color, $ttf, $copy);
header("Content-type: image/png");
ImagePng($dst);
ImageDestroy($src);
ImageDestroy($dst);
}
unset($image);
unset($extension);
}
?>