note 51538 added to ref.image

From: Date: Sun, 03 Apr 2005 02:51:48 +0000
Subject: note 51538 added to ref.image
Groups: php.notes 
Request: Send a blank email to php-notes+get-87387@lists.php.net to get a copy of this message
Hi, it's my second post on php.net. This example can be called 'funny', bot not too usefull :P. The script transforms a true-color image in a html colorized. Lookout: <? // image2asci - test script // by sn4g <snagnever@gmail.com> // simple script that read "each" pixel from a image and // outputs an html colorized version of it. works fine // with truecolor images, but working on it, maybe can // work with any format. $file = "/all/public_html/stuff/avatar.png; // here we create from a png, but can be from any jpg/png/bmp... if( file_exists($file) ) $src_id = imagecreatefrompng($file); else die("No such file '$file'"); if( $src_id ){ $x_size = imagesx($src_id); $y_size = imagesy($src_id); // if it really read each pixel, it'd be too slow and heavy. so, here we determine // how many pixels the script must 'jump' each loop. tip: y jump must be greater // than the x jump, to decrease the distorcion. $x_jump = 2; $y_jump = 3; // char/strings that will construct the image. it's randomly selected after, // in the loop. a value in the array will be one pixel in the asci-image. $pixel_char = array(0,8); echo "The image is $x_size x $y_size\n"; echo "<span style='font-size:8px; font-weight:bold;'>"; echo "<pre>"; // now it has a 'nested loop' to read 'each' pixel and print it for( $y = 0; $y < $y_size; $y+=$y_jump ){ for( $x = 0; $x < $x_size; $x+=$x_jump ){ if( $x >= $x_size || $y >= $y_size ) break; $rgb = @imagecolorat($src_id, $x, $y); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; if( $x >= $x_size ) break; if( $y >= $y_size ) break; $pc = rand(0,count($pixel_char)-1); $pc = $pixel_char[$pc]; echo "<font style='color:rgb($r,$g,$b)'>$pc</font>"; } // end of 'x' loop echo "\r\n"; // end of a line } // end of 'y' loop } ?> ---- Manual Page -- http://www.php.net/manual/en/ref.image.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51538 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51538&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51538&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51538&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51538&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51538&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51538&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87387) next »