使用包含其他图像的GD创建图片 [英] Create a picture with GD containing other images
问题描述
我想在PHP中创建一张由不同其他图片组成的GD图片。例如,我有6张图片(或更多),我想创建一张包含这些不同图片的图片。
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.
难度是我的最终图片必须有一个固定的宽度和高度(304x179),因此如果不同的图片太大,则必须剪切。这是IconFinder的一个例子:
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 :
这张图片有6张图片http://cdn.iconfinder.net/design/images/_thumbs/is_twitter.png
这张图片由6张图片组成,但切割第3只鸟(绿色),在底部切割4,5和6。这就是我想要的,你能帮我用PHP编写这段代码吗?
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 ?
谢谢
推荐答案
创建主图像并将其视为画布。
Create your primary image and consider it your "canvas."
从那里,使用 imagecopy()将较小的图像复制到画布图像中。
From there, use imagecopy() to copy the smaller images into the canvas image.
请参阅此示例:
<?php
header('Content-Type: image/jpg');
$canvas = imagecreatetruecolor(304, 179);
$icon1 = imagecreatefromjpeg('icon.jpg');
$icon2 = imagecreatefromjpeg('icon2.jpg');
// ... add more source images as needed
imagecopy($canvas, $icon1, 275, 102, 0, 0, 100, 100);
imagecopy($canvas, $icon2, 0, 120, 0, 0, 100, 100);
// ... copy additional source images to the canvas as needed
imagejpeg($canvas);
?>
在我的例子中, icon.jpg
是我放置在画布上的100x100图像,其左上角位于画布中的275,102处,切断了右侧。
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.
编辑
我将代码调整为与您正在进行的操作更相似。
I adjusted the code to be more similar to what you're doing.
这篇关于使用包含其他图像的GD创建图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!