|
|
|
|
|
|
| |
| <?php
/************************************************
** Image to ASCII
**
** Author.: leapinglangoor [ leapinglangoor@yahoo.co.in ]
** Date...: 12th Dec 2004
** ver....: v1.00
**
** desc...: Send an argument $filename and $dir
** The image can be png, jpeg or gif only.
** Use filename such as some.jpeg, langoors.gif, xhtml.png
** $dir - The path of the directory where the image is located
**
************************************************/
function ascii( $filename, $dir )
{
$name = basename( $filename );
$file = $dir . $name;
if( file_exists( $file ) )
{
$what = getimagesize( $file );
switch( $what['mime'] )
{
case 'image/png' : $src_id = imagecreatefrompng( $file );
break;
case 'image/jpeg': $src_id = imagecreatefromjpeg( $file );
break;
case 'image/gif' : $old_id = imagecreatefromgif( $file );
$src_id = imagecreatetruecolor( $what[0],$what[1]);
imagecopy( $src_id, $old_id, 0, 0, 0, 0, $what[0], $what[1] );
break;
default: break;
}
}
else
{
die( 'No such 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);
echo "The image is $x_size x $y_size\n";
echo "<span style='font-size:6px; 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 = 'WM';
echo "<font style='color:rgb($r,$g,$b)'>WM</font>";
} // end of 'x' loop
echo "\r\n"; // end of a line
} // end of 'y' loop
echo "</pre></span>"; // close opened tags
} // end if( $src_id )
} //end function ascii
?> | |
Example usage
| <?php
$image = 'logo.jpg';
$dir = './';
ascii( $image, $dir ); // The ascii will be output by itself
?> | | |
|
| Create Thumbnails - resize an image - jpeg, jpg, gif, png to the specifed width and height in proportion without loosing out on pixcel quality. Categories : PHP, GD image library, Graphics | | | crop and resize image class using gd library function Categories : PHP, PHP Classes, GD image library, Graphics | | | PHP Email image generator - hide your email from bots - using the GD Library Categories : PHP, Graphics, GD image library, Beginner Guides | | | A damaged image generator (class) for validating text.
CAPTCHA - Completely Automated Public Turing test to tell Computers and Humans Apart Categories : PHP, PHP Classes, Security, GD image library, Security | | | Popup window creator for images on the Fly. Categories : PHP, GD image library, Java Script | | | Display a bar chart based on random values. Categories : Graphics, PHP, GD image library, Charts and Graphs | | | ASCII To HTML Converter Categories : PHP, HTML, ASCII | | | Line graphics generation library written in PHP + GD library (spanish comments) Categories : PHP, Graphics, GD image library | | | PHPDRAW, the php wannabe Photoshop ;-) Categories : PHP, PHP Classes, GD image library, Arrays | | | Advanced Image WaterMarker Categories : PHP, PHP Classes, GD image library, Graphics, Object Oriented | | | Simple class that uses GD to draw pie charts. After the class definition there's some sample code to demonstrate how you use the class.
Categories : Graphics, PHP, PHP Classes, GD image library, Charts and Graphs | | | Dynamic Image Authentication System in Signup Pages (CAPTCHA) Categories : PHP, Security, GD image library | | | Creates a CAPTCHA image in PHP, which displays 5 numbers stored in a session. Categories : PHP, GD image library, Form Processing, Security | | | Simple PHP Bar Graph using GD library Categories : PHP, GD image library, Graphics, Arrays | | | CAPTCHA[Image verification] Categories : PHP, Security, GD image library, Graphics, Sessions | |
|
|
|