Jump to content

Can't get imagecopymerge or imagecopy to work combining two png files

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
SloanThrasher

SloanThrasher

    Newbie

  • Members
  • Pip
  • 9 posts
Hi all,

I gotten some great help debugging the script I'm working on, but I have one problem left to overcome.

Quote

Update:
I've built a simple page that shows what I'm trying to do, and what's happening. A picture is worth a 1000 words, and I'm not sure I've described the problem clearly enough.

Take a look here: Sample Page
Basically, I load two images. Both are the exactly same size, color-space, etc. The first image is the background image, and covers the entire width and height of the image. The second image is an image with transparency.

I get the same result with both imagecopy and imagecopymerge. The resulting image shows only the background image. I've swapped the two images, and again, only the first (background) image shows in the result.

The intended result is that the background image is covered by the non-transparent parts of the second image.

Here's the code:

<?php

#$basedir="/LeenaLures/images/Custom Lure pics/LureParts/";
$basedir="../images/Custom Lure pics/LureParts/";
$SizeFolder = "1024x768/";
$BackgroundImg = "background_03.png";
#$BackgroundImg = "jig.png";

$tmp_image = $basedir.$SizeFolder.$BackgroundImg;

if (file_exists($tmp_image)) {
    if (1==1) {
        $imBg = imagecreatefrompng($tmp_image);
        $ImgX = imagesx($imBg);
        $Imgy = imagesy($imBg);
#$ImgX = 1024;
#$ImgY = 768;

        $tmp_image = $basedir.$SizeFolder."jig.png";
#        $tmp_image = $basedir.$SizeFolder."background_03.png";
        $imJig = imagecreatefrompng($tmp_image);

        imagecopymerge($imBg, $imJig, 0, 0, 0, 0, $ImgX, $ImgY,100);
#        imagecopymerge($imBg, $imJig, 0, 0, 0, 0, $ImgX, $ImgY,100);
#        imagecopy($imBg, $imJig, 0, 0, 0, 0, $ImgX, $ImgY);

        header("Content-Type: image/png");
        header("Last-Modified: $last_modified");
        header("File-Name:test.png");
        imagepng($imBg);
        imagedestroy($imBg);

        imagedestroy($imJig);

    } else {
        header("Content-Type: text/txt");
        header("File-Name:test.txt");
        echo "File Found: ".$tmp_image;
    }
} else {
    header("Content-Type: text/txt");
    header("File-Name:test.txt");
    echo "File Not Found: ".$tmp_image;
}

?> 
If someone help me find the right answer to getting the desired result - before I pull out all my hair ;) -- It would be greatly appreciated!!

Also, thanks to all that helped me get the script working so far!!!! :thumbup:

Sloan

Edited by SloanThrasher, 29 June 2010 - 11:20 AM.


#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
imagecopymerge($imBg, $imJig, 0, 0, 0, 0, 0, $ImgX, $ImgY);

#3
SloanThrasher

SloanThrasher

    Newbie

  • Members
  • Pip
  • 9 posts
Hi John,

That doesn't match the docs for the parameters.
Syntax in the docs:
bool  imagecopymerge (resource $dst_im, resource  $src_im, int  $dst_x, int  $dst_y, int  $src_x, int  $src_y, int  $src_w, int  $src_h, int  $pct )
I did put that in, but it still just displays the first image. Did you have a chance to view the "Sample Page" link above?

Thanks

#4
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
Oh right. I was using the parameters for imagecopy. I see nothing apparently wrong with your code. I've attached a very basic working example of what you are trying to do. Take a look at that and see if you can modify it to fit your needs.

Attached Files



#5
SloanThrasher

SloanThrasher

    Newbie

  • Members
  • Pip
  • 9 posts
Thank You, Thank You, Thank You!!

That actually worked!! I thought I had tried that early on, but apparently I didn't try that exact thing.

Thanks for helping me out while I still have some hair left!!

#6
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
No problem. Glad I could help.