Logo
JPEG to ASCII Converter
Online Now: 2
Snippet Code
Take a JPG image, and convert it to ASCII code!
<html>  
<head>  
<title>Ascii</title>  
<style>  
body{  
    line-height:1px;  
    font-size:1px;  
}  
</style>  
</head>  
<body>  
<?php  
function getext($filename) {  
    
$pos strrpos($filename,'.');  
    
$str substr($filename$pos);  
    return 
$str;  
}  
$image 'image.jpg'
$ext getext($image);  
if(
$ext == ".jpg"){  
    
$img ImageCreateFromJpeg($image);  
}  
else{  
    echo
'Wrong File Type';  
}  
$width imagesx($img);  
$height imagesy($img);  

for(
$h=0;$h<$height;$h++){  
    for(
$w=0;$w<=$width;$w++){  
        
$rgb ImageColorAt($img$w$h);  
        
$r = ($rgb >> 16) & 0xFF;  
        
$g = ($rgb >> 8) & 0xFF;  
        
$b $rgb 0xFF;  
        if(
$w == $width){  
            echo 
'<br>';  
        }else{  
           echo 
'<span style="color:rgb('.$r.','.$g.','.$b.');">#</span>'
        }  
    }  
}  
?>
</body>
</html>
 
Snippet Comments

Add Your Comment

650-296
2011-06-09 22:21:11
Woah. This creates high-quality ASCII images. I\'m worried if it will use too much bandwidth or not.
värdering hus 
2011-06-02 22:56:19
Its so much interesting
jaktfilmer
2011-06-02 22:55:32
keep it up!!!!!!!!!!!!!!!1
kreditkort
2011-06-02 22:53:48
I like it so much
vir0e5
2011-03-14 03:48:47
nice code sir!!
Coding for Everyone
2011-01-03 15:36:08
Thanks for the script. I am going to use it on my website..
xahoi
2010-12-16 07:20:22
Awesome... thank for share
expertise online
2010-12-08 19:27:21
Nice code, I've seen a couple sites using this.
php tutorial
2010-11-28 16:53:15
Nice code!
PHPKode
2010-09-13 23:47:27
well. nice script. thank you.
Kent UK
2010-07-17 00:00:00
Hi I wondered if anyone can help, I need the same function for Gif, BMP and PNG images. This code worked but I need the images in different formats now thanks Marget
CasTex
2009-11-23 00:00:00
Jpg is sometimes gives errors. Thats why I prefer png.
craig
2009-07-23 00:00:00
I keep getting a parse error for line 53. Is there a ; missing somewhere?
ed
2009-06-04 00:00:00
Solved. Needed to give it a php extension of course, not an html
Anonymous
2009-06-04 00:00:00
apparently php seems to have problems with the double 'greater than signs' in the lines as: $r = ($rgb >> 16) & 0xFF;, which makes it think the php code already stops
ed
2009-06-04 00:00:00
That would be 'fishhook open'?echo $_SERVER['PHP_SELF'];?fishhook closed behind teh url and that is an unknown url
ed
2009-06-04 00:00:00
That would be: behind the URl and that is reported as unknown
ed
2009-06-04 00:00:00
Interesting, too bad it does not work though: when pressing the 'Create' button. Th epost method calls for which is an unknown url
Anonymous
2009-05-09 00:00:00
seriously? you whine about people "taking credit" for this? wow...
Link for Mondrak
2009-03-23 00:00:00
Ach ! the link was stripped ! Click on Mondrak link. Sorry

Add Your Comment

 
Snippet Tools
Rate this Snippet:

Rate the difficulty level:

Request Snippet Update


Suggested Difficulty Level: Novice
Current Score: 3.22
Total votes: 427
Total Views: 41742

Other top snippets by admin:

1. Add (th, st, nd, rd, th) to the end of a number
2. Dynamic Page Content From Links
3. AJAX Quickie
4. Simple Image CAPTCHA
5. Logout Inactive User

Search
Search for:







User Panel

User name:

Password:

Register And Post Your Own Snippets

New Snippets

1.  Shorten text and (4 of 1)

2.  file-based simple guest (0 of 0)

3.  adding an entry (0 of 0)

4.  integer to currency (1.33 of 3)

5.  Aggregate IP addresses (0 of 0)

6.  file handling (0 of 0)

7.  testing system with (0 of 0)

8.  Make an php (1 of 1)

9.  allow download in (5 of 1)

10.  redirect in 3 (0 of 0)

11.  live clock with (0 of 0)

12.  visit counter (3.5 of 2)

13.  contact form with (4 of 1)

14.  show a specific (0 of 0)

15.  The & sign (0 of 0)

16.  static variable in (0 of 0)

17.  multiplication table with (0 of 0)

18.  function with multiplicationt (0 of 0)

19.  php generated menu (0 of 0)

20.  drawing a table (0 of 0)

21.  embedded array (one (0 of 0)

22.  checks the week (0 of 0)

23.  put links on (4.5 of 2)

24.  Directory Image Gallery (0 of 0)

25.  TOS (4 of 1)

Home | Forum | Free PHP Web Hosting | Contact | Terms & Conditions |  
Donate
PHPSnips.com - ©2012 Amethyst Creative