note 87238 added to ref.image

From: Date: Wed, 26 Nov 2008 05:18:26 +0000
Subject: note 87238 added to ref.image
Groups: php.notes 
Request: Send a blank email to php-notes+get-146971@lists.php.net to get a copy of this message
I wrote a simple function to convert an image resource to PGM (portable graymap) in order to feed it to an OCR program. It works just like the rest of the image output functions, and will convert to grayscale for you: <?php function imagepgm($image, $filename = null) { $pgm = "P5 ".imagesx($image)." ".imagesy($image)." 255\n"; for($y = 0; $y < imagesy($image); $y++) { for($x = 0; $x < imagesx($image); $x++) { $colors = imagecolorsforindex($image, imagecolorat($image, $x, $y)); $pgm .= chr(0.3 * $colors["red"] + 0.59 * $colors["green"] + 0.11 * $colors["blue"]); } } if($filename != null) { $fp = fopen($filename, "w"); fwrite($fp, $pgm); fclose($fp); } else { return $pgm; } } ?> ---- Server IP: 208.69.120.35 Probable Submitter: 71.65.214.198 ---- Manual Page -- http://www.php.net/manual/en/ref.image.php Edit -- https://master.php.net/note/edit/87238 Del: integrated -- https://master.php.net/note/delete/87238/integrated Del: useless -- https://master.php.net/note/delete/87238/useless Del: bad code -- https://master.php.net/note/delete/87238/bad+code Del: spam -- https://master.php.net/note/delete/87238/spam Del: non-english -- https://master.php.net/note/delete/87238/non-english Del: in docs -- https://master.php.net/note/delete/87238/in+docs Del: other reasons-- https://master.php.net/note/delete/87238 Reject -- https://master.php.net/note/reject/87238 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#146971) next »