WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Keep your PC away from viruses - Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Convert PNG, JPEG and GIF images to ASCII
Categories : PHP, ASCII, GD image library Click here to Update Your Picture
leaping langoor
Date : Apr 27th 2005
Grade : 3 of 5 (graded 11 times)
Viewed : 26280
File : No file for this code example.
Images : No Images for this code example.
Search : More code by leaping langoor
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?php

/************************************************
** Image to ASCII
**
** Author.: leapinglangoor [ [email protected] ]
** 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
?>



PHPDRAW, the php wannabe Photoshop ;-)
Categories : PHP, PHP Classes, GD image library, Arrays
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
Creates a CAPTCHA image in PHP, which displays 5 numbers stored in a session.
Categories : PHP, GD image library, Form Processing, Security
Create a Thumbnail Using PHP, GD and Exif
Categories : PHP, Graphics, Exif, GD image library
Display a bar chart based on random values.
Categories : Graphics, PHP, GD image library, Charts and Graphs
Image Browser
Categories : Filesystem, GD image library, Content Management, PHP
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
PHP Email image generator - hide your email from bots - using the GD Library
Categories : PHP, Graphics, GD image library, Beginner Guides
PHP Image Class
Categories : PHP, PHP Classes, Multimedia, GD image library
Advanced Image WaterMarker
Categories : PHP, PHP Classes, GD image library, Graphics, Object Oriented
ASCII To HTML Converter
Categories : PHP, HTML, ASCII
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
Image Generation Class ( PNG Format )
Categories : PHP, GD image library, PHP Classes, Graphics
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel