我有一个将用户数据和图像上传到服务器上的数据库和文件夹的表单。我正在调整图像的大小,以使其宽度不大于1200像素。 因此,代码的第一部分(此工作开始)工作正常。 但是我尝试制作第二张宽度为400px的图像并保存到另一个文件夹的第二部分不起作用。 为什么会这样,有人有主意吗?
谢谢。
//This Works start
$save_th = $uploadfolder_th . "/" . $upload_DstName[$i]; //This is the new file you saving
$save = $uploadfolder . "/" . $upload_DstName[$i]; //This is the new file you saving
$file = $uploadfolder . "/" . $upload_DstName[$i]; //This is the original file
list($width, $height) = getimagesize($file) ;
$modwidth = 1200;
$diff = $width / $modwidth;
$modheight = $height / $diff;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 80) ;
//This Works end
//--------------------------------------------------------------------------------------------------
//This is not Working start
$modwidth_th = 400;
$diff_th = $width / $modwidth_th;
$modheight_th = $height / $diff_th;
$tn_th = imagecreatetruecolor($modwidth_th, $modheight_th) ;
$image_th = imagecreatefromjpeg($file) ;
imagecopyresampled($tn_th, $image_th, 0, 0, 0, 0, $modwidth_th, $modheight_th, $width, $height) ;
imagejpeg($tn_th, $save_th, 80) ;
//This is not Working end