合并使用php创建的两个图像

时间:2016-06-28 11:36:41

标签: php

如何合并从url两个url创建的两个图像,如:

合并这两张图片:

`$ URL1 = https://imageare.com/nc/Aud/tr.php?track=426413219-.wav&ignorable_duration=1.0

$url2=https://imageare.com/nc/Aud/tr.phptrack=426413219_chan1.wav&ignorable_duration=1.0

与可能的副本不同:未提取图像

2 个答案:

答案 0 :(得分:0)

示例

$url1 = "https://imageare.com/nc/Aud/tr.phptrack=426413219_chan1.wav&ignorable_duration=1.0";
$png_image = imagecreatefromfile($url1);
function imagecreatefromfile($filename) {
    if(!file_exists($filename)) {
        throw new InvalidArgumentException('File "'.$filename.'" not found.');
    }
    switch(strtolower(pathinfo($filename, PATHINFO_EXTENSION))) {
        case 'jpeg':
        case 'jpg':
            return imagecreatefromjpeg($filename);
        break;

        case 'png':
            return imagecreatefrompng($filename);
        break;

        case 'gif':
            return imagecreatefromgif($filename);
        break;

        default:
            throw new InvalidArgumentException('File "'.$filename.'" is not valid jpg, png or gif image.');
        break;
    }
}

答案 1 :(得分:0)

要合并两个图像,如此处所示,并假设图像位于png中。您可能需要使用以下代码:

$url1=https://imageare.com/nc/Aud/tr.php?track=426413219-.wav&ignorable_duration=1.0
$url2=https://imageare.com/nc/Aud/tr.phptrack=426413219_chan1.wav&ignorable_duration=1.0
$dest = imagecreatefrompng($url1);
$src = imagecreatefrompng($url2);
imagecopymerge($dest, $src, 0, 0, 0, 0, 500, 100, 90);

以下内容可用于将图像输出到浏览器

header('Content-Type: image/png');
imagepng($dest);