gpt4 book ai didi

使用最近邻插值调整 PHP 图像大小?

转载 作者:可可西里 更新时间:2023-11-01 13:51:32 26 4
gpt4 key购买 nike

我有一个 PNG 或 GIF 图像格式的 16x16 子画面,我想在网站上以 64 x 64 的所有像素化荣耀显示它。在 Firefox 3.6+ 和 IE 中,我可以使用 image-rendering and -ms-interpolation-mode 通过 CSS 轻松完成此操作,但由于这在所有浏览器中都不起作用,所以我想改用 PHP 动态调整图像大小。在 PHP 中使用最近邻插值调整图像大小的最佳方法是什么?

最佳答案

如果你想在调整大小时保持像素化,你会想使用 GD 库做这样的事情:

<?php
// create GD image resource from source image file
$src = imagecreatefromgif('test.gif');

// create new GD image resource with indexed color
$dest = imagecreate(64, 64);

// copy/resize image without resampling
imagecopyresized($dest, $src, 0, 0, 0, 0, 64, 64, 16, 16);

// output result
header('Content-type: image/gif');
imagegif($dest);
?>

我已经测试了代码,像素化保持完好。您必须调整代码以接受 png 文件作为输入,这应该相当容易,因为每个 GD gif 函数也有相应的 png 函数。希望这会有所帮助。

关于使用最近邻插值调整 PHP 图像大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4530767/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com