note 115609 added to function.imagecolorat

From: Date: Sun, 24 Aug 2014 22:00:35 +0000
Subject: note 115609 added to function.imagecolorat
Groups: php.notes 
Request: Send a blank email to php-notes+get-200309@lists.php.net to get a copy of this message
To test whether to handle the return value of this function as RGB or a palette index, see either imageistruecolor(), or (for GD < 2.0.1, or PHP 4 < 4.3.2) imagecolorstotal() == 0. It seems that a number of comments here take many lines to convert RGB or RGBA values to hex strings #AARRGGBB. This is a one-liner in most cases: $hex = sprintf("#%08X", imagecolorat($im32, $x, $y)); $hex = sprintf("#%08X", $rgb); $hex = sprintf("#%08X", $argb); $hex = sprintf("#%02X%06X", $rgba >> 24, $rgba & 0xFF000000); $hex = sprintf("#00%02X%02X%02X", $r, $g, $b); $hex = sprintf("#%02X%02X%02X%02X", $a, $r, $g, $b); For paletted images, it's two lines: $cols = imagecolorsforindex($imPal, imagecolorat($imPal, $x, $y)); $hex = sprintf("#%08X", $cols['alpha'], $cols['red'], $cols['green'], $cols['blue']); ---- Server IP: 72.52.91.14 Probable Submitter: 70.114.130.6 ---- Manual Page -- http://php.net/manual/en/function.imagecolorat.php Edit -- https://master.php.net/note/edit/115609 Del: integrated -- https://master.php.net/note/delete/115609/integrated Del: useless -- https://master.php.net/note/delete/115609/useless Del: bad code -- https://master.php.net/note/delete/115609/bad+code Del: spam -- https://master.php.net/note/delete/115609/spam Del: non-english -- https://master.php.net/note/delete/115609/non-english Del: in docs -- https://master.php.net/note/delete/115609/in+docs Del: other reasons-- https://master.php.net/note/delete/115609 Reject -- https://master.php.net/note/reject/115609 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#200309) next »