...

Image Textifier...

bacterozoid
09-23-2009, 09:53 PM
Useless, but fun. Here's a screenshot.

http://bit.ly/3BhaLG

Basically, you give it an image (PNG or JPG/JPEG is all I wrote support for), set some effects, and run the script. You then get a bunch of text.

You can use a glow effect, use random characters or one you specify, force "wobble removal" by using the "courier" font so characters are monospaced, or use your own custom text. Mix and match effects, try it out.

It's not nearly as cool as http://text-image.com/, but it's still a little bit of fun. ;) Requires the GD library to run.

Here's the script:


<html>
<head>
<title>Effect</title>
<style>
body {background-color: black; }
</style>
</head>
<body>
<div style="text-align: center; width: 100%">

<?php

/* You can change this stuff */
/* */

$dpx = 9; // Pixel differential - The samller you make this, the larger the image (and the time it takes to make it)
$repl = '#'; // Character to use in the image. Using effects may alter this
$font = 'arial'; // Font to use for the text. Using effects may alter this
$image_name = 'image.png'; // Name of the picture to use

/* Adds a glow to the image, radiating from the center */
$effect_glow = true;

/* Uses random characters to form the image */
$effect_random_char = true;
/* The random characters you want to allow */
$random_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890-=[];,.!@#$%^&*()_+|}{":?><~';

/* When enabled, the font is set to what you chose above. This will enable variable character lenghts and create a weird-looking image */
$effect_wobble = true;

/* Uses your text string to form the image */
/* NOTE: THIS OVERRIDES EFFECT_RANDOM_CHAR */
$effect_my_text = false;
/* The text string for your image */
$my_text = 'I can place whatever text I want here and then it will be used to create the image. Cool, huh?';

/* */
/* Ok, that's it for the settings */

$ext = strtolower(substr(strrchr($image_name, '.'), 1));

switch($ext) {
case 'png':
$image = imagecreatefrompng($image_name);
break;

case 'jpg':
case 'jpeg':
$image = imagecreatefromjpeg($image_name);
break;
}

$DPY = $dpx * 2; // When font is courier (evenly spaced), multiplier helps set image dimensions better.
list($w, $h) = getimagesize($image_name);

// Effect setup
if($effect_glow) {
$center_x = $w/2;
$center_y = $h/2;
$max_distance = sqrt(pow((1-$center_x),2) + pow((1-$center_y),2));
}
if(!$effect_wobble) {
$font = 'courier'; // Required so image dimensions are preserved
}
if($effect_my_text) {
$my_text_length = strlen($my_text);
$current_my_text_index = 0;
}


/*** GENERATE ***/
echo '<span style="font-family: ' . $font . '">';
// Then go down
for($i = 0; $i < $h; $i += $DPY) {
// Go across first
for($j = 0; $j < $w; $j += $dpx) {
$rgb = getRGBArray($image, $j, $i);

if($effect_glow) {

// Find distance from center
$distance = sqrt(pow(($j-$center_x),2) + pow(($i-$center_y),2));

// Determine how clearly to show this segment
$percent_shown = abs($distance/$max_distance) * 100;

// Determine the RGB loss
$loss = round(255 * $percent_shown/100);

// Keep loss within valid range due to rounding error
if($loss > 255) $loss = 255;
if($loss < 0) $loss = 0;

$rgb[0] -= $loss; if($rgb[0] < 0) $rgb[0] = 0;
$rgb[1] -= $loss; if($rgb[1] < 0) $rgb[1] = 0;
$rgb[2] -= $loss; if($rgb[2] < 0) $rgb[2] = 0;
}

if($effect_random_char) {
$repl = $random_chars[mt_rand(0, strlen($random_chars)-1)];
}

if($effect_my_text) {
if($current_my_text_index > $my_text_length-1) $current_my_text_index = 0; // Wraparound
$repl = $my_text[$current_my_text_index];
$current_my_text_index++;
}

$style = 'color: rgb(' . $rgb[0] . ',' . $rgb[1] . ',' . $rgb[2] . ')';
echo '<span style="' . $style . '">' . $repl . '</span>';
}
echo '<br/>';
}
echo '</span>';


function getRGBArray($image, $x, $y) {
$rgb = imagecolorat($image, $x, $y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
return array($r, $g, $b);
}

?>
</div>
</body>
</html>

abduraooft
09-24-2009, 08:24 AM
Haven't tried the above one, but there's a very compact script at http://php.net/manual/en/function.imagestring.php#86763

bacterozoid
09-24-2009, 12:14 PM
Ah, that one is very cool. A combination of the two would yield a very nice little script. Right now I just output text. He outputs an image by using imagestring, which I like better.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum