我有一个带有几个图标的 sprite,大约 30 个。我通过设置一个特定图标的背景位置来使用它们。但是现在,我想像图像一样使用一个图标,例如将它们放在 facebook og:img 元标记中..
那么,如何通过 php 和 GD 生成图标呢?
mydomain.com/generate_icon.php?icon_id=5
没有GD还有其他方法吗?
最佳答案
我如何用 GD 或其他方法做到这一点..对不起我的英语!!
这里是一个 WITH GD 的例子
$no = isset($_GET['no']) ? $_GET['no'] : 0; <---- Image Number via GET
$img = "sprites.png";
list($h, $w) = getimagesize($img);
$size = ($h < $w) ? $h : $w;
$src = imagecreatefrompng($img);
$dest = imagecreatetruecolor($size, $size);
imagecopy($dest, $src, 0, 0, 0, ($size * $no), $size, $size);
// Output and free from memory
header('Content-Type: image/png');
imagegif($dest);
用法 image.php?no=5
关于php - 从图像 sprite、css 和 php 生成图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13113610/