note 109787 modified in function.imagefilledrectangle by danbrown

From: Date: Fri, 31 Aug 2012 15:49:24 +0000
Subject: note 109787 modified in function.imagefilledrectangle by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-190339@lists.php.net to get a copy of this message
I wanted to clear an image, and set it to full transparent.&#13;&#10;imagefilledrectangle() seems to ignore alpha channel and alpha blending.&#13;&#10;Use imagefill() instead:&#13;&#10;&#13;&#10;&#60;?php&#13;&#10;$w = imagesx($final);&#13;&#10;$h = imagesy($final);&#13;&#10;$grande = imagecreatetruecolor($w, $h);&#13;&#10;&#13;&#10;// Alpha blending on to use channel alpha&#13;&#10;imagealphablending($grande, true);&#13;&#10;// Allocate a transparent color and fill the new image with it.&#13;&#10;// Without this the image will have a black background instead&#13;&#10;// of being transparent.&#13;&#10;$transparent = imagecolorallocatealpha($grande, 0, 0, 0, 127);&#13;&#10;// transparent alpha will be _ignored_:&#13;&#10;imagefilledrectangle($grande, 0, 0, $w, $h, $transparent);&#13;&#10;// ok, transparent will be used and set whole alpha channel to transparent:&#13;&#10;imagefill($grande, 0, 0, $transparent);&#13;&#10;?&#62; --was-- I wanted to clear an image, and set it to full transparent. imagefilledrectangle() seems to ignore alpha channel and alpha blending. Use imagefill() instead: <php $w = imagesx($final); $h = imagesy($final); $grande = imagecreatetruecolor($w, $h); // Alpha blending on to use channel alpha imagealphablending($grande, true); // Allocate a transparent color and fill the new image with it. // Without this the image will have a black background instead // of being transparent. $transparent = imagecolorallocatealpha($grande, 0, 0, 0, 127); // transparent alpha will be _ignored_: imagefilledrectangle($grande, 0, 0, $w, $h, $transparent); // ok, transparent will be used and set whole alpha channel to transparent: imagefill($grande, 0, 0, $transparent); ?> http://php.net/manual/en/function.imagefilledrectangle.php

« previous php.notes (#190339) next »