我想拍摄一张具有透明度的图像,然后将其覆盖在60x60(任意尺寸)图像的顶部,该图像重复第一张图像的宽度和长度......
因此,基本上使用图像2作为图像1位于其上方的重复背景图像。
修改
好吧,所以我使用了One Trick Pony的解决方案,但是如果宽度小于高度,则尝试修改它以从矩形中创建方形图像,但是不能拉伸原始图像而是将其居中。我能够使图像居中,但是在叠加图像停止后重复背景不会继续重复。
以下是代码:
<?php
$overlay = imagecreatefrompng('../images/' . $_REQUEST['overlay']);
$repeating = '../images/' . $_REQUEST['repeating'];
$ext = explode('.', $_REQUEST['repeating']);
$ext = strtolower($ext[1]);
if ($ext == 'gif')
$repeating = imagecreatefromgif($repeating);
elseif ($ext == 'png')
$repeating = imagecreatefrompng($repeating);
elseif ($ext == 'jpg' || $ext == 'jpeg')
$repeating = imagecreatefromjpeg($repeating);
$w = imagesx($overlay);
$h = imagesy($overlay);
if ($w < $h)
$w = $h;
$output = imagecreatetruecolor($w, $h);
imagealphablending($output, true);
imagesettile($output, $repeating);
imagefill($output, 0, 0, IMG_COLOR_TILED);
imagedestroy($repeating);
$offsetx = ($w - imagesx($overlay)) / 2;
imagecopy($output, $overlay, $offsetx, 0, 0, 0, $w, $h);
imagedestroy($overlay);
header('Content-Type: image/png');
imagepng($output);
imagedestroy($output);
?>
编辑2:
重叠:http://72.167.52.68/~viisi/ebaylist/images/back_test2.png
重复:http://72.167.52.68/~viisi/ebaylist/images/back_test.gif
预期结果(但在整个图像中继续重复):http://72.167.52.68/~viisi/ebaylist/image/previewImage.php?overlay=back_test2.png&repeating=back_test.gif
答案 0 :(得分:3)
$overlay = imagecreatefrompng('/path/to/transparent/image.png');
$repeating = imagecreatefrompng('/path/to/repeating/image.png');
// create a new image matching overlay size
$w = imagesx($overlay);
$h = imagesy($overlay);
$output = imagecreatetruecolor($w, $h);
imagealphablending($output, true);
imagesavealpha($output, true);
// tile repeating image on it
imagesettile($output, $repeating);
imagefill($output, 0, 0, IMG_COLOR_TILED);
imagedestroy($repeating);
// now add overlay on top
imagecopy($output, $overlay, 0, 0, 0, 0, $w, $h);
imagedestroy($overlay);
// send to screen
header('Content-Type: image/png');
imagepng($output);
imagedestroy($output);