2017-02-16 108 views
0

我正在尝试使用2个不同的PNG图像创建图像,但我无法使其工作。没有错误或任何东西,但我没有得到一个图像创建。从2张图像创建图像

另外,是否有可能在最终图像上放置一些文本,然后保存它(硬编码文本)?

测试样品

<?php 
    $image_1 = imagecreatefrompng('assets/img/image_body.png'); 
    $image_2 = imagecreatefrompng('assets/img/img_2.png'); 
    imagealphablending($image_1, true); 
    imagesavealpha($image_1, true); 
    imagecopy($image_1, $image_2, 0, 0, 0, 0, 100, 100); 
    imagepng($image_1, 'image_3.png'); 
?> 

回答

0

$_SERVER['DOCUMENT_ROOT']; 

此代码工作改变图像的位置。

<?php 
// This .php file is inside root>NP 
$LOC = $_SERVER['DOCUMENT_ROOT']; 
$image_1 = imagecreatefrompng($LOC . '/NP/m1.png'); 
$image_2 = imagecreatefrompng($LOC . '/NP/m2.png'); 
imagealphablending($image_1, true); 
imagesavealpha($image_1, true); 
imagecopy($image_1, $image_2, 0, 0, 0, 0, 640, 400); 
imagepng($image_1, $LOC.'/NP/m3.png'); 
?> 
+0

位置与它有什么关系? –