且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何调整图像大小而不将其存储在文件夹中

更新时间:2022-11-05 20:36:37

这是你的大问题:

return $dst;

$ dst 是图片资源,不是图像数据。

$dst is the image resource, not the image data.

您应该使用 imagejpeg() imagepng()改为发送图像数据。

You should use imagejpeg() or imagepng() to send the image data back instead.

因为这些函数将数据流输出到浏览器,我们使用一些输出缓冲函数来捕获输出的图像数据而不是发送它到浏览器。

Because those functions output the data stream to browser, we use some output buffer functions to capture the outputted image data instead of send it to the browser.

所以,

return $dst;

替换为:

ob_start();
imagejpeg( $dst, NULL, 100); // or imagepng( $dst, NULL, 0 );
$final_image = ob_get_contents();
ob_end_clean();
return $final_image;