1

How can i merge two image created from url two url like:

Merge these two images:

`$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

Not same as the possible duplicate: Image not fetched

  • Possible duplicate of [Merging two images with PHP](http://stackoverflow.com/questions/3876299/merging-two-images-with-php) – Ctc Jun 28 '16 at 11:39
  • Different as the images are not stored but formed.Plus, this doent seem to work –  Jun 28 '16 at 11:40
  • Have you tried actually retrieving the URL and checked that you get image data? Have you tried using imagecreatefromstring to read the image? Have you used finfo_buffer to check the type of the data returned? Have you tried fetching the data to a file first, then read it with imagepng? Are you able to retrieve other files from the same host? – MatsLindh Jul 03 '16 at 13:15

2 Answers2

0

Example

$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;
    }
}
Fabio Widmer
  • 529
  • 1
  • 7
  • 19
0

To merge two images like shown here and assuming that images are in png .You might need to use following code:

$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);

The following can be used to output image to browser

header('Content-Type: image/png');
imagepng($dest);
Lucky
  • 575
  • 3
  • 18