The imagecopy function beats colors when overlaying

The question is this: I am reading the article Photomontage in PHP. But the author’s example doesn’t work for some reason, it breaks the colors for some reason:

<?php 
header("Content-type: image/png");
$res = imagecreate(120,120); 
$img = imagecreatefromjpeg("photo.jpg");
$mask = imagecreatefrompng("border.png"); 
$logo = imagecreatefrompng("logo.png");
$green = imagecolorallocate($res,136,203,44);
imagecopyresized ($res,$img,
 0,0,
 0,0,
 120,120,
 imagesx($img),imagesy($img));
imagecopy ($res,$logo,60,110,0,0,60,12);
/*int imagecopy ( ,  ,   ,   ,      ,      ,  ,  )*/
imagecopy ($res,$mask,0,0,0,0,120,120);
$trans = imagecolorat($res,0,0);
imagecolortransparent($res,$trans);
imagepng($res);
?>

Why is this happening? In the example of the author on the site, everything is fine. I downloaded his own example, the colors even beat with his example. What is the reason?


Answer 1, authority 100%

For starters, remove the last two characters in the first line, and it will be visible there. =)

UPD:
instead of

$res = imagecreate(120,120);

should be

$res = imagecreatetruecolor(120,120);

And one more point, as a bonus =) To make the quality better when reducing the picture, you need instead

imagecopyresized ($res,$img,

write

imagecopyresampled ($res,$img,

Answer 2

Try imagecreatetruecolor()instead of imagecreate().