如何保存PHP图像处理输出


How to save the output of PHP image processing

我不确定这个函数是否做了我打算做的事情,但我需要的是在文件夹中创建图像的缩略图。

$filename = '../images/' . $new_name;
header('Content-Type: image/jpeg');
list($width, $height) = getimagesize($filename);
$new_width = $width / $height;
$new_height = 250 / $new_width;
$new_height = round($new_height);
$image_p = imagecreatetruecolor(250, $new_height);
$image_s = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image_s, 0, 0, 0, 0, 250, $new_height, $width, $height);
imagejpeg($image_p, null, 100);

所以我需要将最终结果保存到我的文件夹中,但不要覆盖原始图像。我在http://php.net/上找到了这个函数,但我不知道如何保存图像。

imagejpeg($image_p, "path/to/dir/image.jpg", 100);