我在简单的基本PHP图像调整时遇到了一个问题。
我传递我的图像在POST使用AJAX调用..
这是我的PHP代码://resize original image
switch ($type) {
case "desktop":
$width = 1920;
$height = 1080;
break;
case "mobile":
$width = 640;
$height = 1080;
break;
}
print_r("start resize");
print_r('<br>');
$size = getimagesize($url);
$img_origX = imagesx($img_orig);
$img_origY = imagesy($img_orig);
//height (Auto calculate)
//$height = round($width*$size[1]/$size[0]);
$img = imagecreatetruecolor($width, $height);
imagecopyresampled($img, $img_orig, 0, 0, 0, 0, $width, $height, $img_origX, $img_origY);
// Output
header('Content-type: image/jpg');
imagejpeg($img , "thumbnail.jpg");
$imageData = fopen("thumbnail.jpg", "r");
print_r("resize ok");
print_r('<br>');
问题是,在网络中,我从来没有收到"调整大小ok",出错了…
顺序正确吗?
删除print_r
,当您输出图像时,它应该只有图像的数据。如果只输出图像,则只需要imagejpeg
: imagejpeg($img);
中的一个参数为什么打开$imageData = fopen("thumbnail.jpg", "r");
文件?这对于输出图像