note 49024 added to function.imagecolortransparent

From: Date: Fri, 14 Jan 2005 16:17:24 +0000
Subject: note 49024 added to function.imagecolortransparent
Groups: php.notes 
Request: Send a blank email to php-notes+get-83276@lists.php.net to get a copy of this message
Wow! I am actually surprized there are no functions to retrieve transparency information from the image. I assume I'm not missing anything since there are all kinds of notes about how to get around this limitation. At any rate, here is some code to read the gif file and retrieve the missing information. The code will speak volumes. <?php class GifInfo { var $m_transparentRed; var $m_transparentGreen; var $m_transparentBlue; var $m_signature; var $m_version; var $m_width; var $m_height; var $m_width; var $m_height; var $m_colorFlag; var $m_backgroundIndex; function GifInfo($filename) { $fp = fopen($filename,"rb"); $result = fread($fp,13); $this->m_signature = substr($result,0,3); $this->m_version = substr($result,3,3); $this->m_width = ord(substr($result,6,1)) + ord(substr($result,7,1)) * 256; $this->m_height = ord(substr($result,8,1)) + ord(substr($result,9,1)) * 256; $this->m_colorFlag = ord(substr($result,10,1)) >> 7; $this->m_background = ord(substr($result,11)); if($this->m_colorFlag) { $tableSizeNeeded = ($this->m_background + 1) * 3; $result = fread($fp,$tableSizeNeeded); $this->m_transparentRed = ord(substr($result,$this->m_background * 3,1)); $this->m_transparentGreen = ord(substr($result,$this->m_background * 3 + 1,1)); $this->m_transparentBlue = ord(substr($result,$this->m_background * 3 + 2,1)); } fclose($fp); } } ?> And to use this class.... <?php $size = getimagesize($userfile); $img2 = ImageCreate($w,$h); $gi = new GifInfo($userfile); if($gi->m_version == '89a' && $gi->m_colorFlag == 1) { $transparent = imagecolorallocate($img2, $gi->m_transparentRed, $gi->m_transparentGreen, $gi->m_transparentBlue); imagecolortransparent ($img2,$transparent); } ?> ---- Manual Page -- http://www.php.net/manual/en/function.imagecolortransparent.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49024 Delete -- http://master.php.net/manage/user-notes.php?action=delete+49024&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49024&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+49024&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+49024&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+49024&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+49024&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+49024&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#83276) next »