note 89927 added to function.imagecolortransparent

From: Date: Sun, 29 Mar 2009 14:48:54 +0000
Subject: note 89927 added to function.imagecolortransparent
Groups: php.notes 
Request: Send a blank email to php-notes+get-152578@lists.php.net to get a copy of this message
I've made a very simple script that will retain transparency of images especially when resizing. NOTE: Transparency is only supported on GIF and PNG files. Parameters: $new_image = image resource identifier such as returned by imagecreatetruecolor(). must be passed by reference $image_source = image resource identifier returned by imagecreatefromjpeg, imagecreatefromgif and imagecreatefrompng. must be passed by reference function setTransparency($new_image,$image_source) { $transparencyIndex = imagecolortransparent($image_source); $transparencyColor = array('red' => 255, 'green' => 255, 'blue' => 255); if ($transparencyIndex >= 0) { $transparencyColor = imagecolorsforindex($image_source, $transparencyIndex); } $transparencyIndex = imagecolorallocate($new_image, $transparencyColor['red'], $transparencyColor['green'], $transparencyColor['blue']); imagefill($new_image, 0, 0, $transparencyIndex); imagecolortransparent($new_image, $transparencyIndex); } Sample Usage: (resizing) $image_source = imagecreatefrompng('test.png'); $new_image = imagecreatetruecolor($width, $height); setTransparency($new_image,$image_source); imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height); ---- Server IP: 209.41.74.194 Probable Submitter: 222.127.171.211 ---- Manual Page -- http://www.php.net/manual/en/function.imagecolortransparent.php Edit -- https://master.php.net/note/edit/89927 Del: integrated -- https://master.php.net/note/delete/89927/integrated Del: useless -- https://master.php.net/note/delete/89927/useless Del: bad code -- https://master.php.net/note/delete/89927/bad+code Del: spam -- https://master.php.net/note/delete/89927/spam Del: non-english -- https://master.php.net/note/delete/89927/non-english Del: in docs -- https://master.php.net/note/delete/89927/in+docs Del: other reasons-- https://master.php.net/note/delete/89927 Reject -- https://master.php.net/note/reject/89927 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#152578) next »