将php中创建的两个图像合并为一个
我有以下输出/显示为PNG/PHP图像的PHP脚本: -image.php -background.php 我希望能够打开第三个脚本“main.php”,它显示image.php覆盖在background.php上 我尝试过使用常用的方法:将php中创建的两个图像合并为一个,php,image,merge,Php,Image,Merge,我有以下输出/显示为PNG/PHP图像的PHP脚本: -image.php -background.php 我希望能够打开第三个脚本“main.php”,它显示image.php覆盖在background.php上 我尝试过使用常用的方法: <?php $url1="image.php" $url2="background.php"; $dest = imagecreatefrompng($url1); $src = imagecreatefromjpeg($url2);
<?php
$url1="image.php"
$url2="background.php";
$dest = imagecreatefrompng($url1);
$src = imagecreatefromjpeg($url2);
imagecopymerge($dest, $src, 10, 9, 0, 0, 181, 180, 100);
header('Content-Type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);
?>
但这并没有起作用(大概是因为cource图像是php)
关于如何合并这两个图像有什么想法吗?提前感谢您需要向php解释,它需要执行image.php,而不是以其“原始”形式包含它。 我能想到的最简单的方法是使用类似curl_init或file_get_contents的东西,并将完整的url添加到php脚本中,这样您就可以通过http打开文件,并要求web服务器为您执行它 因此,请将代码更改为以下内容:
<?php
$url1= file_get_contents("http://example.com/image.php");
$url2= file_get_contents("http://example.com/background.php");
$dest = imagecreatefrompng($url1);
$src = imagecreatefromjpeg($url2);
imagecopymerge($dest, $src, 10, 9, 0, 0, 181, 180, 100);
header('Content-Type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);
?>
嗯,
bovako您应该尝试使用
include
读取文件内容,然后使用imagecreatefromstring
创建图像:
<?php
$handle = imagecreatefromstring(include('image.php'));
谢谢,它现在似乎正在工作。我必须将imagecreate函数从png/JPEG更改为string(如下所示):
再次感谢!使我的头脑免于发疯
$url1= file_get_contents("http://example.com/image.php");
$url2= file_get_contents("http://example.com/background.php");
$dest = imagecreatefromstring($url1);
$src = imagecreatefromstring($url2);
imagecopymerge($dest, $src, 10, 9, 0, 0, 181, 180, 100);
header('Content-Type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);
?>