我有一个表单,用户可以上传他的图像,单击“提交”后,我尝试调整图像的大小并制作同一图像的另一个副本以获取缩略图,调整第一张图像的大小非常有用,但是当它用于缩略图时它有时甚至有时没有,我不知道这是与hostgator共享服务器有关的问题还是其逻辑代码内部的问题,这是我的代码:
if($extens == 'JPEG' || $extens == 'JPG' || $extens == 'jpg' )
{
list($width, $height) = @getimagesize($path);
$newwidth = $width > $newwidth ? $newwidth : $width;
$newheight = $height > $newheight ? $newheight : $height;
$src = @imagecreatefromjpeg($path);
if($width > $height)
{
$var = $width / $newwidth;
$newwidth = $newwidth;
$newheight = $height / $var;
}elseif($width < $height)
{
$var = $height / $newheight;
$newheight = $newheight;
$newwidth = $width / $var;
}
//resizing first image
$temp12 = imagecreatetruecolor($newwidth, $newheight);
$black2 = imagecolorclosestalpha($temp12,250,249,249,85);
imagecopyresampled($temp12, $src, 0,0,0,0, $newwidth, $newheight, $width, $height);
Imagettftext($temp12, 16, 0, $start_x, $start_y, $black2, $font , "mywebsite.com");
imagejpeg($temp12, $path,95);
//resizing for a thumbnail
$temp2 = imagecreatetruecolor($newwidth1, $newheight2);
imagecopyresampled($temp2, $src, 0,0,0,0, $newwidth1, $newheight2, $width, $height);
Imagettftext($temp2, 8, 0, $start_x2, $start_y2, $black2, $font , "mywebsite.com");
imagejpeg($temp2,$pathFile ,95);
imagedestroy($temp2);
imagedestroy($temp12);
imagedestroy($src);
//there is elseif of png same logic except imagejpeg and
// }elseif($extens == 'png' || $extens == 'PNG'){