note 59797 added to function.imagecolorat
| From: | robert at future-vision dot nl | Date: | Fri, 16 Dec 2005 00:53:38 +0000 |
| Subject: | note 59797 added to function.imagecolorat | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-100271@lists.php.net to get a copy of this message | ||
Look mom, no tables :)
I made some changes to the code from 'hazard AT krankteil DOTTILLYDO de' so the function
would output a div that displays the image.
As for the size of the outputted file I can say the original png file was lots smaller, but maybe
its a nice feature for small buttons or such.
The way you can use it is the same as the code from 'hazard AT krankteil DOTTILLYDO de'.
litle note: each div contains a bogus image. When this is not in IE will screw up the output.
<?
function hexcolor($c) {
$r = ($c >> 16) & 0xFF;
$g = ($c >> 8) & 0xFF;
$b = $c & 0xFF;
return '#'.str_pad(dechex($r), 2, '0', STR_PAD_LEFT).str_pad(dechex($g),
2, '0', STR_PAD_LEFT).str_pad(dechex($b), 2, '0', STR_PAD_LEFT);
}
function png2div($filename) {
$img = imagecreatefrompng($filename);
$width = imagesx($img);
$height = imagesy($img);
$div_width = 1;
$previous_color = 0;
$output = '<div style="position:relative;width:' . $width .
'px;height:'. $height .'px;">';
for($y = 0;$y < $height;++$y){
for($x = 0;$x < $width;++$x){
$current_color = ImageColorAt($img, $x, $y);
if($current_color == $previous_color && $x < $width-1){
++$div_width;
}
else{
$output .= '<div style="position:relative;float:left;width:' . $div_width .
'px;height:1px;background-color:' . hexcolor((($div_width > 1)?
$previous_color:$current_color)) . '"><img src="bogus.gif"
alt="" width="1" height="1" /></div>';
$previous_color = $current_color;
$div_width = 1;
}
}
ob_flush();
}
$output .= '</div>';
return $output;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagecolorat.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59797
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59797&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59797&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59797&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59797&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59797&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59797&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59797&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59797&report=yes
Search -- http://master.php.net/manage/user-notes.php