PHP: How can i marge 2 images on top of each others, and maintaining the transparency.

I have this http://visionplayz.com/test/ .... How can i make the right image to go on top of the T-Shirt and both of the images to be transparent.
 Looking to become something like that: http://visionplayz.com/test/demo.png
I am using this code:


<?php

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


//Set the 2 file names.
$resOriginalImage1='male.png';
$resOriginalImage2='test4.png';

//Image 1 Details
$image_details1 = getimagesize($resOriginalImage1);

if ($image_details1 === false){
      echo 'Not a valid image supplied, or this script does not have permissions to access it.';

}else{
      $Original_W1 = $image_details1[0];
      $Original_H1 = $image_details1[1];
      $type1 = $image_details1[2];
      $mime1 = $image_details1['mime'];
}

switch ($type1){
      case 1:
            //      GIF
            $source1 = imagecreatefromgif($resOriginalImage1);
            break;
            
      case 2:
            //      JPG
            $source1 = imagecreatefromjpeg($resOriginalImage1);
            break;
            
      case 3:
            //      PNG
            $source1 = imagecreatefrompng($resOriginalImage1);
            break;
            
      default:
            echo 'Unsupported image file format.';
            
}


$image_details2 = getimagesize($resOriginalImage2);

if ($image_details2 === false){
      echo 'Not a valid image supplied, or this script does not have permissions to access it.';

}else{
      $Original_W2 = $image_details2[0];
      $Original_H2 = $image_details2[1];
      $type2 = $image_details2[2];
      $mime2 = $image_details2['mime'];
}

switch ($type2){
      case 1:
            //      GIF
            $source2 = imagecreatefromgif($resOriginalImage2);
            break;
            
      case 2:
            //      JPG
            $source2 = imagecreatefromjpeg($resOriginalImage2);
            break;
            
      case 3:
            //      PNG
            $source2 = imagecreatefrompng($resOriginalImage2);
            break;
            
      default:
            echo 'Unsupported image file format.';
            
}
    //Set new Image Dimensions
      $newWidth = $Original_W1 + $Original_W2;
      $newHeight = $Original_H1;

    //create holder for new image
      $resResizedImage = imagecreatetruecolor($newWidth, $newHeight);
      imagealphablending($resResizedImage, false);
      imagesavealpha($resResizedImage, true);

      
      //Copy both images into the new image
      imagecopyresampled($resResizedImage, $source1, 0, 0, 0, 0, $Original_W1, $Original_H1, $Original_W1, $Original_H1);
      imagecopyresampled($resResizedImage, $source2, $Original_W1, 100, 100, 0, $Original_W2, $Original_H2, $Original_W2, 100);

      //Save the New PNG File.
      imagepng($resResizedImage);


?>
RobakoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.