note 54404 added to function.imagecopy

From: Date: Sun, 03 Jul 2005 11:45:21 +0000
Subject: note 54404 added to function.imagecopy
Groups: php.notes 
Request: Send a blank email to php-notes+get-91347@lists.php.net to get a copy of this message
Just a little function that allows you to change the foreground color of a transparent gif or png. It's supposed to use only two-color images, becouse it convert all the colors to the specified one. It works with .gif or .png as source, but writes only .png function ColorReplace( $url ) { # The new color and its channels $NEW_COLOR = "#FF66FF"; $r = 0+("0x".substr( $NEW_COLOR, 1, 2)); $g = 0+("0x".substr( $NEW_COLOR, 3, 2)); $b = 0+("0x".substr( $NEW_COLOR, 5, 2)); # I read the kind of file from the extension $tmp = pathinfo($url); $extension =$tmp['extension']; if( $extension == 'png' ) $oldIm = @imagecreatefrompng( $url ); elseif( $extension == 'gif' ) $oldIm = @imagecreatefromgif( $url ); # I replace EACH color in the palette with the new one for( $i=0; $i < imagecolorstotal( $oldIm ); $i++ ) imagecolorset( $oldIm, $i, $r,$g,$b ); # Output the file in png format : each color is now NEW COLOR # but transparency is preserved !! header("Content-type: image/png"); imagepng($oldIm); imagedestroy($oldIm); } ---- Manual Page -- http://www.php.net/manual/en/function.imagecopy.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54404 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54404&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54404&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54404&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54404&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54404&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54404&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54404&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91347) next »