Вы можете попробовать эту функцию.
function thumb($file, $save, $width, $height)
{
@unlink($save);
if (!$infos = @getimagesize($file)) {
return false;
}
$iWidth = $infos[0];
$iHeight = $infos[1];
$iRatioW = $width / $iWidth;
$iRatioH = $height / $iHeight;
$iNewW = $width;
$iNewH=($iHeight/$iWidth)*$iNewW;
//$iNewH = $height;
//Don't resize images which are smaller than thumbs
if ($infos[0] < $width && $infos[1] < $height) {
$iNewW = $infos[0];
$iNewH = $infos[1];
}
if($infos[2] == 1) {
$imgA = imagecreatefromgif($file);
$imgB = imagecreate($iNewW,$iNewH);
if(function_exists('imagecolorsforindex') && function_exists('imagecolortransparent')) {
$transcolorindex = imagecolortransparent($imgA);
//transparent color exists
if($transcolorindex >= 0 ) {
$transcolor = imagecolorsforindex($imgA, $transcolorindex);
$transcolorindex = imagecolorallocate($imgB, $transcolor['red'], $transcolor['green'], $transcolor['blue']);
imagefill($imgB, 0, 0, $transcolorindex);
imagecolortransparent($imgB, $transcolorindex);
//fill white
} else {
$whitecolorindex = @imagecolorallocate($imgB, 255, 255, 255);
imagefill($imgB, 0, 0, $whitecolorindex);
}
//fill white
} else {
$whitecolorindex = imagecolorallocate($imgB, 255, 255, 255);
imagefill($imgB, 0, 0, $whitecolorindex);
}
imagecopyresampled($imgB, $imgA, 0, 0, 0, 0, $iNewW, $iNewH, $infos[0], $infos[1]);
imagegif($imgB, $save);
} elseif($infos[2] == 2) {
$imgA = imagecreatefromjpeg($file);
$imgB = imagecreatetruecolor($iNewW,$iNewH);
imagecopyresampled($imgB, $imgA, 0, 0, 0, 0, $iNewW, $iNewH, $infos[0], $infos[1]);
imagejpeg($imgB, $save);
} elseif($infos[2] == 3) {
/*
* Image is typ png
*/
$imgA = imagecreatefrompng($file);
$imgB = imagecreatetruecolor($iNewW, $iNewH);
imagealphablending($imgB, false);
imagecopyresampled($imgB, $imgA, 0, 0, 0, 0, $iNewW, $iNewH, $infos[0], $infos[1]);
imagesavealpha($imgB, true);
imagepng($imgB, $save);
} else {
return false;
}
return true;
}
thumb($source,$target_full_path,'337','208');