我有一个脚本可以保存图像两次,一个用于高质量,一个用于拇指。图像的移动有效但调整大小没有。有人有线索吗?我安装了GD
$newImgName = RandomString(6) . '_' . rand(10, 99);
$newCoverImg = '../images/news/'. $newImgName .'.jpg';
$newThumbImg = '../images/news/'. $newImgName .'_thumb.jpg';
copy($_POST['article_cover'], $newCoverImg);
copy($_POST['article_cover'], $newThumbImg);
$percent = 0.5;
list($width, $height) = getimagesize($newThumbImg);
$newwidth = $width * $percent;
$newheight = $height * $percent;
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($newThumbImg);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
答案 0 :(得分:1)
你应该写 imagecopyresized 而不是 imagecopyresampled 你的代码应该是这样的
$newImgName = RandomString(6) . '_' . rand(10, 99);
$newCoverImg = '../images/news/'. $newImgName .'.jpg';
$newThumbImg = '../images/news/'. $newImgName .'_thumb.jpg';
copy($_POST['article_cover'], $newCoverImg);
copy($_POST['article_cover'], $newThumbImg);
$percent = 0.5;
list($width, $height) = getimagesize($newThumbImg);
$newwidth = $width * $percent;
$newheight = $height * $percent;
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($newThumbImg);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);