Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts

    combining images - png24 (GD)

    I'm using imagecopy to combine 2 images. One is just a solid colour created by php, the other is a png-24. Basically I want to put the png-24 on top of the solid colour so that it shows through the transparent and translucent parts.

    However what happens is the transparency completely overwrites the underlying pixels, so that any page background colour is visible but not the base image.

    Am I just dreaming? Is this going to be possible? If it can be done with GD can it be done with imagemagick?

    PHP Code:
    <?php
    //Send a generated image to the browser
    create_image();


    function 
    create_image()
    {

        
    //Set the image width and height
        
    $width 220;
        
    $height 220

        
    //Create the image resource 
        
    $image ImageCreate($width$height);  

        
    $fill ImageColorAllocate($imagerand(0,255), rand(0,255), rand(0,255));


        
    //Make the background black 
        
    ImageFill($image00$fill); 
         
    ImagePNG($image'testcolor.png');


       
    $overlay imagecreatefrompng('ponyshade.png');
       
    imageAlphaBlending($overlaytrue);
       
    imageSaveAlpha($overlaytrue);
       
    imagecopy($image,$overlay,0,0,0,0,220,220);


        
    //Output the newly created image in jpeg format 
        
    ImagePNG($image'test.png');
       
    ImagePNG($overlay'testover.png');
        
    //Free up resources
        
    ImageDestroy($image); 
      }
    ?>
    <div style = "background-color:#FF00FF">
    <image src = "testcolor.png"/>
    <image src = "test.png"/><image src = "testover.png"/>
    </div>

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    I'm not sure about this but I found this which uses imagecopymerge instead of imagecopy.

  • #3
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    imagecopymerge doesnt respect alphatransparency.

    ...looks like I've found the problem. The background image has to be imagecreatetruecolor - not just imagecreate. All works fine now.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •