用GD创建一张包含其他图像的图片
我想用PHP用GD创建一张由不同的其他图片组成的图片。例如,我有 6 张图片(或更多),我想创建一张包含这些不同图片的图片。
困难在于我的最终图片必须具有固定的宽度和高度(304x179),因此如果不同的图片太大,则必须将其剪切。这是来自 IconFinder 的示例:
这张图片由 6 张图片组成,但第 3 只鸟(绿色)被剪掉,第 4、5、6 只被剪在底部。这就是我想要的,你能帮我用 PHP 编写这段代码吗?
谢谢
I would like to create a picture in PHP with GD composed by different other pictures. For example I have 6 pictures (or more) and I would like to create ONE picture who contain these different pictures.
The Difficulty is that my final picture must have a fixed width and height (304x179), so if the different pictures are too big they must be cut. This is an example from IconFinder :
This picture is composed by 6 images, but the 3rd bird (green) is cutted, and the 4, 5 and 6 are cutted in the bottom. This is what I want, can you give me some help to write this code in PHP ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建您的主要图像并将其视为您的“画布”。
从那里,使用 imagecopy() 将较小的图像复制到画布中图像。
例如:
在我的示例中,
icon.jpg
是一个 100x100 的图像,我将其放置在画布中,使其左上角位于画布中的 275, 102 处,这会截断右侧。编辑
我调整了代码,使其更类似于您正在做的事情。
Create your primary image and consider it your "canvas."
From there, use imagecopy() to copy the smaller images into the canvas image.
See this for example:
In my example,
icon.jpg
is a 100x100 image which I am placing in the canvas such that its top left corner is located at 275, 102 in the canvas, which cuts off the right side.Edit
I adjusted the code to be more similar to what you're doing.
这是我的一个脚本中未经测试的修改 spinet,希望它有用:
Here a none tested modify spinet from one of my scripts, hope it can be usefull: