An Image is Worth a Thousand Words in PHP Continued - In Conclusion (
Page 5 of 5 )
That's it. We now have a working conversion library - but we still haven't seen how it works! Let's try it out by converting a familiar graphic. Go ahead and create a file - (you can name it anything you like, so long as it has a .php extension) - and put in it the following code:
<html>
<head>
<title>IMG_TO_TXT</title>
<style type="text/css">
strong, b {
color: #FFFFFF;
font-family: Tahoma, Arial, Verdana, Helvetica, sans-serif;
font-size: 11px;
}
</style>
</head>
<body bgcolor="#000000">
<?php
include_once 'img_to_txt.php';
$img_to_txt = new img_to_txt();
$img_to_txt->set_chars( 'MYNAMEISBRIAN' );
?>
<b>Color:</b><br>
<?php
$img_to_txt->load_image( 'http://www.google.com/intl/en/images/logo.gif' );
echo $img_to_txt->get_image();
?>
<br><b>Grayscale:</b><br>
<?php
$img_to_txt->set_return_format( 'grayscale' );
echo $img_to_txt->get_image();
?>
<br><b>Matrix:</b><br>
<?php
$img_to_txt->set_return_format( 'matrix' );
echo $img_to_txt->get_image();
?>
<br><b>Monochrome:</b><br>
<?php
$img_to_txt->set_return_format( 'monochrome' );
echo $img_to_txt->get_image();
?>
</body>
</html>
The above demonstration converts the familiar Google image into several text-only modes. You may view this example online here:
http://images.devshed.com/ds/stories/Image_is_Words/IMG_TO_TXT.htm
If you have not followed along but would still like to download the source code, it may be found online here:
http://images.devshed.com/ds/stories/Image_is_Words/img_to_txt.zip
I hope this has been a useful exercise for any of you who have taken the time to complete it. Thank you for your time, and please let me know if you have any questions/comments. Until next time...