Пришлось помучатся, стыдно за нерабочий код, плюсы получать, тэстил на фотках с твоего сайта, вроде всё работает, пробуй (выкладываю всю функцию целиком):
function createImageAndThumb($src_file,$image_name,$thumb_name,
$max_width,
$max_height,
$max_width_t,
$max_height_t,
$tag,
$path,
$orig_name)
{
global $mosConfig_absolute_path;
$types = array(
IMAGETYPE_JPEG => 'jpeg',
IMAGETYPE_GIF => 'gif',
IMAGETYPE_PNG => 'png'
);
ini_set('memory_limit', '64M');
$src_file = urldecode($src_file);
/*if (extension_loaded('exif'))
{
$type2 = exif_imagetype($src_file);
$types = array(
IMAGETYPE_JPEG => 'jpeg',
IMAGETYPE_GIF => 'gif',
IMAGETYPE_PNG => 'png'
);
$type = $types[$type2];
}
else
{*/
$orig_name = strtolower($orig_name);
$findme = '.jpg';
$pos = strpos($orig_name, $findme);
if ($pos === false)
{
$findme = '.jpeg';
$pos = strpos($orig_name, $findme);
if ($pos === false)
{
$findme = '.gif';
$pos = strpos($orig_name, $findme);
if ($pos === false)
{
$findme = '.png';
$pos = strpos($orig_name, $findme);
if ($pos === false)
{
return;
}
else
{
$type = "png";
}
}
else
{
$type = "gif";
}
}
else
{
$type = "jpeg";
}
}
else
{
$type = "jpeg";
}
//}
$max_h = $max_height;
$max_w = $max_width;
$max_thumb_h = $max_height_t;
$max_thumb_w = $max_width_t;
if ( file_exists( "$path/$image_name")) {
unlink( "$path/$image_name");
}
if ( file_exists( "$path/$thumb_name")) {
unlink( "$path/$thumb_name");
}
$read = 'imagecreatefrom' . $type;
$write = 'image' . $type;
$src_img = $read($src_file);
// height/width
$imginfo = getimagesize($src_file);
$src_w = $imginfo[0];
$src_h = $imginfo[1];
$zoom_h = $max_h / $src_h;
$zoom_w = $max_w / $src_w;
$zoom = min($zoom_h, $zoom_w);
$dst_h = $zoom<1 ? round($src_h*$zoom) : $src_h;
$dst_w = $zoom<1 ? round($src_w*$zoom) : $src_w;
$zoom_h = $src_h/ $max_thumb_h ;
$zoom_w = $src_w/ $max_thumb_w;
$zoom = round(min($zoom_h, $zoom_w));
$dst_thumb_h = $max_thumb_h;
$dst_thumb_w = $max_thumb_w;
$dst_img = imagecreatetruecolor($dst_w,$dst_h);
$white = imagecolorallocate($dst_img,255,255,255);
imagefill($dst_img,0,0,$white);
imagecopyresampled($dst_img,$src_img, 0,0,0,0, $dst_w,$dst_h,$src_w,$src_h);
$textcolor = imagecolorallocate($dst_img, 255, 255, 255);
if (isset($tag))
imagestring($dst_img, 5, 5, 5, "$tag", $textcolor);
if($type == 'jpeg'){
$desc_img = $write($dst_img,"$path/$image_name", 80);
}else{
$desc_img = $write($dst_img,"$path/$image_name", 2);
}
// создание превьюшек загружаемы
$dst_t_img = imagecreatetruecolor($dst_thumb_w,$dst_thumb_h);
$white = imagecolorallocate($dst_img,255,255,255);
imagefill($dst_t_img,0,0,$white);
if ($zoom_h == $zoom_w) {
imagecopyresampled($dst_t_img, $src_img,
0, 0,
0, 0,
$dst_thumb_w, $dst_thumb_h,
$src_w, $src_h);
}
if ($zoom_w < $zoom_h) {
imagecopyresampled($dst_t_img, $src_img,
0, 0,
0, round($src_h/2-($zoom*$dst_thumb_h)/2),
$dst_thumb_w, $dst_thumb_h,
$src_w, ($zoom*$dst_thumb_h));}
if ($zoom_w > $zoom_h) {imagecopyresampled($dst_t_img, $src_img,
0, 0,
round($src_w/2-($zoom*$dst_thumb_w)/2), 0,
$dst_thumb_w, $dst_thumb_h,
($zoom*$dst_thumb_w),$src_h ); }
//imagecopyresampled($dst_t_img, $src_img, 0, 0,
// 0,round($src_h/2 - $src_w/4),
// 100, 50, $src_w, round($src_w/2));
$textcolor = imagecolorallocate($dst_t_img, 255, 255, 255);
if (isset($tag))
imagestring($dst_t_img, 2, 2, 2, "$tag", $textcolor);
if($type == 'jpeg'){
$desc_img = $write($dst_t_img,"$path/$thumb_name", 75);
}else{
$desc_img = $write($dst_t_img,"$path/$thumb_name", 2);
}
}