使用 GD 调整图像大小而不丢失颜色

发布于 2024-12-15 01:51:45 字数 257 浏览 1 评论 0原文

我正在尝试使用 GD 调整图像大小,但发现调整大小后的图像出现颜色损失。这是我的代码:

$src = imagecreatefromstring(file_get_contents($source)); 
ImageCopyResized($dst, $src, 0, 0, 0, 0, $t_width, $t_height, ImageSX($src), ImageSY($src)); 
Imagejpeg($dst, $dest, 90);

I'm trying to resize an image with GD and am seeing a color loss on the resized image. Here is my code:

$src = imagecreatefromstring(file_get_contents($source)); 
ImageCopyResized($dst, $src, 0, 0, 0, 0, $t_width, $t_height, ImageSX($src), ImageSY($src)); 
Imagejpeg($dst, $dest, 90);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

信仰 2024-12-22 01:51:45

您在声明 $ 时是否使用 imagecreatetruecolor目的地

Are you using imagecreatetruecolor when declaring $dst?

盗心人 2024-12-22 01:51:45

正确的方法是:

$dst = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($dst, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

The right way to do this is:

$dst = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($dst, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文