note 111591 added to book.imagick

From: Date: Wed, 06 Mar 2013 19:09:30 +0000
Subject: note 111591 added to book.imagick
Groups: php.notes 
Request: Send a blank email to php-notes+get-193964@lists.php.net to get a copy of this message
Here's a handy function that finds the first occurrence of a specific pixel. You can set the tolerance of the color you are looking for, or set it to 0 if want an exact match <?php function findPixel($img, $r, $g, $b, $tolerance=5) { $original_ = new Imagick($img); $height = 0; $width = 0; list($width, $height) = getimagesize($img); $matrix_org = array(); $matrix_mrk = array(); for( $x = 0 ; $x < $width ; $x++){ $matrix_org[$x] = array(); $matrix_mrk[$x] = array(); } for( $x = 0 ; $x < $width ; $x++ ) { for( $y = 0 ; $y < $height ; $y++ ){ $matrix_org[$x][$y] = $original_->getImagePixelColor($x, $y)->getColorAsString(); $colors = preg_replace('/[^-,0-9+$]/', '', $matrix_org[$x][$y]); $colors = explode(',', $colors); $r_org = $colors[0]; $g_org = $colors[1]; $b_org = $colors[2]; if( ( $r <= ($r_org+$tolerance) && $r >= ($r_org - $tolerance) ) && ( $g <= ($g_org+$tolerance) && $g >= ($g_org - $tolerance) ) && ( $b <= ($b_org+$tolerance) && $b >= ($b_org - $tolerance) ) ) { return array( $x, $y ); } } } return false; } ?> ---- Server IP: 69.147.83.199 Probable Submitter: 173.63.52.183 ---- Manual Page -- http://php.net/manual/en/book.imagick.php Edit -- https://master.php.net/note/edit/111591 Del: integrated -- https://master.php.net/note/delete/111591/integrated Del: useless -- https://master.php.net/note/delete/111591/useless Del: bad code -- https://master.php.net/note/delete/111591/bad+code Del: spam -- https://master.php.net/note/delete/111591/spam Del: non-english -- https://master.php.net/note/delete/111591/non-english Del: in docs -- https://master.php.net/note/delete/111591/in+docs Del: other reasons-- https://master.php.net/note/delete/111591 Reject -- https://master.php.net/note/reject/111591 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193964) next »