使用 GD 库进行蒙太奇或拼贴画

发布于 2024-10-11 08:58:38 字数 175 浏览 3 评论 0原文

我正在尝试使用 GD 库创建一个缩略图表,例如 100 个 10x10 缩略图。我看到 imagemagick 有一个蒙太奇功能,可能会很有用,但我想知道 GD 库是否也可以做到这一点。

我想我可以通过在一个简单的 html 表中输出所有图像并将该表转换为图像来做到这一点,但看起来这可能是不可能的。有什么帮助或建议吗?

I'm trying to create a table of thumbnails for example 100 thumbnails 10x10 with GD Library. I saw that imagemagick has a montage function that would probably be useful but I'm wondering if GD library can do this as well.

I thought I could maybe do it by just outputting all of the images in a simple html table and converting that table to an image, but it appears that might not be possible. Any help or suggestions?

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

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

发布评论

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

评论(2

绝影如岚 2024-10-18 08:58:38

这绝对是可能的。您可以使用 GD 调整图像大小,以及将图像复制到另一个图像中。要了解有关调整大小的更多信息,请查看我制作的调整大小功能:http://www. Spotlesswebdesign.com/blog.php?id=1

但是,假设您的图像大小已经调整为 10x10,并且您有一个数组,其中包含 100 个指向不同 10x10 gif 的 url。

$montage_image = imagecreatetruecolor(100, 100);
$x_index = 0;
$y_index = 0;
foreach($array_with_100_10x10_gif_urls as $gif_image_url) {
    $current_image = imagecreategif($gif_image_url);
    imagecopy($montage_image, $current_image, $x_index * 10, $y_index * 10, 0, 0, 10, 10);
    imagedestroy($current_image);
    $x_index++;
    if ($x_index > 9) {
        $x_index = 0;
        $y_index++;
    }
}
// place code for saving the montage image as a file or outputting to teh browser here.
imagedestroy($montage_image);

This is most certainly possible. You can resize images, as well as copy images into another image with GD. To find out more about resizing, check out this resize function I made: http://www.spotlesswebdesign.com/blog.php?id=1

But let's say your images are already resized to 10x10, and you had an array filled with 100 urls leading to different 10x10 gifs.

$montage_image = imagecreatetruecolor(100, 100);
$x_index = 0;
$y_index = 0;
foreach($array_with_100_10x10_gif_urls as $gif_image_url) {
    $current_image = imagecreategif($gif_image_url);
    imagecopy($montage_image, $current_image, $x_index * 10, $y_index * 10, 0, 0, 10, 10);
    imagedestroy($current_image);
    $x_index++;
    if ($x_index > 9) {
        $x_index = 0;
        $y_index++;
    }
}
// place code for saving the montage image as a file or outputting to teh browser here.
imagedestroy($montage_image);
把梦留给海 2024-10-18 08:58:38

GD做不到这一点。为什么不直接使用 imagemagick 呢?

编辑:
GD可以做到这一点,但你必须手动完成,没有GD功能可以与imagemagick的蒙太奇相媲美。

GD cant do that. Why not just use imagemagick?

EDIT:
GD can do that, but you'd have to do it manually, there is no GD function comparable to imagemagick's montage.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文