Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Change image color to transparent then use as a mask
    text
    copied!<p>I'm trying to change the background colour of an image from white, to transparent, then to use that as a mask to put over another image. (Cannot be transparent already, because another part is which is used as a mask over yet another image)... layers are fun :)</p> <p>Full code:</p> <pre><code>&lt;? include '../includes/db.php'; include '../includes/checks.php'; $type = $_GET['t']; //shirt | shorts $style = $_GET['s']; $z = $_GET['z']; // home | away $a = $_GET['a']; $b = $_GET['b']; $aR = hexdec($a['0'].$a['1']); $aG = hexdec($a['2'].$a['3']); $aB = hexdec($a['4'].$a['5']); $bR = hexdec($b['0'].$b['1']); $bG = hexdec($b['2'].$b['3']); $bB = hexdec($b['4'].$b['5']); // main top $imgname = '../images/kits/test/'. $uTime .'.png'; $im = imagecreatetruecolor( 100, 100); $red = imagecolorallocate($im, $aR, $aG, $aB); imagefill($im, 0, 0, $red); $mask = imagecreatefrompng('../images/kits/test/6-space.png'); imagecopyresampled($im, $mask, 0, 0, 0, 0, imagesx($im), imagesy($im), imagesx($mask), imagesy($mask)); imagedestroy($mask); $mask = imagecreatefrompng('../images/kits/test/4-shadows.png'); imagecopyresampled($im, $mask, 0, 0, 0, 0, imagesx($im), imagesy($im), imagesx($mask), imagesy($mask)); imagedestroy($mask); $mask = imagecreatefrompng('../images/kits/test/1-tag.png'); imagecopyresampled($im, $mask, 0, 0, 0, 0, imagesx($im), imagesy($im), imagesx($mask), imagesy($mask)); imagedestroy($mask); // design $im2 = imagecreatetruecolor( 100, 100); $red = imagecolorallocate($im2, $bR, $bG, $bB); imagefill($im2, 0, 0, $red); $mask = imagecreatefrompng('../images/kits/test/5-logo.png'); imagecopyresampled($im2, $mask, 0, 0, 0, 0, imagesx($im2), imagesy($im2), imagesx($mask), imagesy($mask)); imagedestroy($mask); imagecolortransparent($im2, imagecolorallocatealpha($im2, 0, 0, 0, 127)); imagealphablending($im2, false); imagesavealpha($im2, true); $white = imagecolorallocate($im2,255,255,255); imagecolortransparent($im2, $white); // merge and result imagecopyresampled($im, $im2, 0, 0, 0, 0, imagesx($im), imagesy($im), imagesx($im2), imagesy($im2)); imagepng($im, $imgname); imagedestroy($im2); imagedestroy($im); echo '&lt;img src="', $imgname ,'"&gt;'; ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload