title: PHP, imagecreate, imagecreatetruecolor, imagecopy, imagecopymerge
body: <p>(1) imagecreate</p>
  
  <p>(2) imagecreatetruecolor</p>
  
  <p>(3) imagecopy</p>
  
  <p>(4) imagecopymerge</p>
  
  <p>I use above PHP function and get confused.</p>
  
  <p>First I prepare two png files...</p>
  
  <p>1.png <a href="http://www.capbite.com/subfolder/lion/test/1.png" rel="nofollow">http://www.capbite.com/subfolder/lion/test/1.png</a></p>
  
  <p>A QRcode with transparent background and black dot, I create it by these code (only keypoint, not all).</p>
  
  <pre><code>$image = imagecreate($width, $height);
  imagesavealpha($image, true);
  $color1 = imagecolorallocatealpha($image, 0, 0, 0, 127);
  imageColorallocate($image, 0, 0, 0);
  imagefill($image, 0, 0, $color1);
  ...
  imagepng($image, $filename);
  </code></pre>
  
  <p>2.png <a href="http://www.capbite.com/subfolder/lion/test/2.png" rel="nofollow">http://www.capbite.com/subfolder/lion/test/2.png</a></p>
  
  <p>I make a png and use a color to fill its background by MS paint.</p>
  
  <p>Prepare done. Then the code is</p>
  
  <pre><code>&lt;?php
  //use imagecreate or imagecreatetruecolor
  $image = imagecreate(50, 50);
  //$image = imagecreatetruecolor(50, 50);
  
  //save the alpha channel
  imagesavealpha($image, true);
  
  //alphablending set false, then transparent color can cover the canvas
  imagealphablending($image, false);
  
  //take a transparent color and fill it
  imagefill($image, 0, 0, imagecolorallocatealpha($image, 0, 0, 0, 127));
  
  //draw the ellipse
  imagefilledellipse($image, 15, 15, 30, 30, imagecolorallocate($image, 255, 0, 0));
  
  imagepng($image, '3.png');
  
  imagedestroy($image);
  
  //merge image
  $im_background = imagecreatefrompng('1.png');
  $im_foreground = imagecreatefrompng('3.png');
  
  list($width, $height) = getimagesize('3.png');
  
  //use imagecopy or imagecopymerge
  imagecopy($im_background, $im_foreground, (int)35, (int)35, 0, 0, $width, $height);
  //imagecopymerge($im_background, $im_foreground, (int)35, (int)35, 0, 0, $width, $height, 100);
  
  imagepng($im_background, 'x-x.png');
  
  imagedestroy($im_background);
  imagedestroy($im_foreground);
  </code></pre>
  
  <p>The code make 3.png like this www.capbite.com/subfolder/lion/test/3.png</p>
  
  <p>Now if I use </p>
  
  <p>1.png + imagecreate + imagecopy will get <a href="http://www.capbite.com/subfolder/lion/test/4-1.png" rel="nofollow">http://www.capbite.com/subfolder/lion/test/4-1.png</a></p>
  
  <p>1.png + imagecreate + imagecopymerge will get <a href="http://www.capbite.com/subfolder/lion/test/4-2.png" rel="nofollow">http://www.capbite.com/subfolder/lion/test/4-2.png</a></p>
  
  <p>1.png + imagecreatetruecolor + imagecopy will get <a href="http://www.capbite.com/subfolder/lion/test/4-3.png" rel="nofollow">http://www.capbite.com/subfolder/lion/test/4-3.png</a></p>
  
  <p>1.png + imagecreatetruecolor + imagecopymerge will get <a href="http://www.capbite.com/subfolder/lion/test/4-4.png" rel="nofollow">http://www.capbite.com/subfolder/lion/test/4-4.png</a></p>
  
  <p>2.png + imagecreate + imagecopy will get <a href="http://www.capbite.com/subfolder/lion/test/5-1.png" rel="nofollow">http://www.capbite.com/subfolder/lion/test/5-1.png</a></p>
  
  <p>2.png + imagecreate + imagecopymerge will get <a href="http://www.capbite.com/subfolder/lion/test/5-2.png" rel="nofollow">http://www.capbite.com/subfolder/lion/test/5-2.png</a></p>
  
  <p>2.png + imagecreatetruecolor + imagecopy will get <a href="http://www.capbite.com/subfolder/lion/test/5-3.png" rel="nofollow">http://www.capbite.com/subfolder/lion/test/5-3.png</a></p>
  
  <p>2.png + imagecreatetruecolor + imagecopymerge will get <a href="http://www.capbite.com/subfolder/lion/test/5-4.png" rel="nofollow">http://www.capbite.com/subfolder/lion/test/5-4.png</a></p>
  
  <p>It is hard to describe the image that made by different ways, so I paste the link about the images, but my reputation is not enough to post more links or images... -- <em>Edited by Niet ;)</em></p>
  
  <p>My question is, just the 3.png, it has a transparent background, even use different create function, but when it copy to another image which I created or by MS paint, the result is I meet.</p>
  
  <p>What's different between imagecreate &amp; imagecreatetruecolor make 4-1.png and 4-3.png ?</p>
  
  <p>What's different between imagecopy &amp; imagecopymerge(even pct set 100) make 4-3.png and 4-4.png ?</p>
  
  <p>What's different between the images which I created or by MS paint make 4-3.png and 5-3.png ?</p>
  
  <p>Thanks a lot!</p>