Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat’s wrong with this PNG Transparent image generator? The background is Black
    primarykey
    data
    text
    <p>First: I want to create a PNG image and draw a shape inside it.</p> <p>Second: Overlap the first PNG on another image (for example a jpg image) The problem is: When I create the first PNG with a shape inside (the background is not transparent and is dark) so this make a black overlap on second image.</p> <p>How can I fix it?</p> <p>I don’t work so much with images function so I got trouble.</p> <p><strong>Notes:</strong> I need to create the first transparent PNG and then overlap it on second image. I don’t want to create shape directly on second image.</p> <p><em><strong>And The Code:</em></strong></p> <pre><code>&lt;?php define('EXAMPLE_TMP_SERVERPATH', ''); define('EXAMPLE_TMP_URLRELPATH', ''); $tempDir = EXAMPLE_TMP_SERVERPATH; $fileName = 'test3img.png'; $imgW = 125; $imgH = 125; # First $base_image = imagecreatetruecolor($imgW, $imgH); $black = imagecolorallocate($base_image, 0, 0, 0); imagecolortransparent($base_image, $black); $col[0] = imagecolortransparent($base_image, $black); imagealphablending($base_image, true); imagesavealpha($base_image, true); imagefill($base_image, 0, 0, $col[0]); imagefilledrectangle($base_image, 4, 4, 50, 25, 255); imagepng($base_image, $tempDir.$fileName); # First2 $target_image = imagecreatetruecolor($imgW*5, $imgH*5); $black2 = imagecolorallocatealpha($base_image, 0, 0, 0, 127); imagecolortransparent($target_image, $black2); imagecopyresized($target_image, $base_image, 0, 0, 0, 0,$imgW, $imgH, $imgW, $imgH); imagedestroy($base_image); imagepng($target_image, $tempDir.$fileName); imagedestroy($target_image); # First2 # Second $dest = imagecreatefromjpeg('../avatar.jpg'); $src = imagecreatefrompng(EXAMPLE_TMP_URLRELPATH.$fileName); imagealphablending($dest, true); imagesavealpha($dest, true); imagealphablending($src, true); imagecopyresampled( $dest, $src, 0,0, 0,0, 200, 200, 125, 125 ); imagepng($dest, EXAMPLE_TMP_URLRELPATH.'_m.jpeg'); imagedestroy($dest); imagedestroy($src); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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