I got really lazy on this.
This class can render text with a 3D perspective and the possibility to change the text rotation and position parameters.
This can be used to generate sequences of images with different views of the same text to produce impressive animations.
Example:PHP Code:<?php
class 3d
{
var $_193;
var $_584;
var $_479;
var $_350;
var $_895;
var $_822;
var $_746;
var $_601;
var $_607;
var $_166;
var $_531;
var $_377;
var $_571;
var $_450;
var $_710;
var $_663;
var $_174;
var $_858;
var $_988;
var $_445;
var $_999;
var $_008;
var $_004;
var $_111;
var $_112;
var $_113;
var $_114;
var $_115;
var $_116;
var $_014 = Array();
var $_147 = Array();
var $_364 = Array();
var $_091 = Array();
var $_303 = Array();
var $_513 = Array();
var $_352 = Array();
var $_726 = Array();
var $_165 = Array();
var $_057 = Array();
var $PI = 3.1415926535897931;
function __construct( $j, $k, $p, $q, $r, $rgb1, $rgb2, $font, $fontsize, $text )
{
$this->_116 = ( $j / 10 ) + 2.0;
$this->_350 = $j <= 0 ? 128 : $j << 4;
$this->_822 = $k <= 0 ? 15 : $k;
$this->_746 = 45500;
$this->_895 = 2;
$this->_584 = 1;
$this->_479 = 0;
$this->_111 = $font;
$this->_112 = $fontsize;
$this->_113 = $text;
$i = $p * 256;
if( $i < 0 )
$i += 0x16800;
$this->_601 = $i // ROTX
$i = $q * 256;
if( $i < 0 )
$i += 0x16800;
$this->_607 = $i; // ROTY
$i = $r * 256;
if( $i < 0 )
$i += 0x16800;
$this->_166 = $i; // ROTZ
$i = 0 * 256;
if( $i < 0 )
$i += 0x16800;
$this->_531 = $i;
$i = 0 * 256;
if( $i < 0 )
$i += 0x16800;
$this->_377 = $i;
$i = 0 * 256;
if( $i < 0 )
$i += 0x16800;
$this->_571 = $i;
for( $i = 0; $i < 181; $i++ )
$this->_726[ $i ] = floor( sin( ( (double)$i / 180 ) * $this->PI ) * 256 );
$this->_450 = $this->rgb2int( $rgb1 );
$this->_352[ 0 ] = $this->rgb2int($ rgb2 );
$ad[ 0 ] = $rgb2[ r ];
$ad[ 1 ] = $rgb2[ g ];
$ad[ 2 ] = $rgb2[ b ];
$ad1[ 0 ] = ( (double)$rgb1[ r ] - $ad[ 0 ] ) / 110;
$ad1[ 1 ] = ( (double)$rgb1[ g ] - $ad[ 1 ] ) / 110;
$ad1[ 2 ] = ( (double)$rgb1[ b ] - $ad[ 2 ] ) / 110;
for( $i = 0; $i < 64; $i++ )
$this->_352[ $i ] = $this->rgb2int( Array(
r => floor( $ad[ 0 ] += $ad1[ 0 ] ),
g => floor( $ad[ 1 ] += $ad1[ 1 ] ),
b => floor( $ad[ 2 ] += $ad1[ 2 ] ) )
);
switch( $this->_479 )
{
case 1:
$this->_663 = 51;
break;
case 0:
$this->_663 = 40;
break;
}
switch( $this->_584 )
{
case 2:
$this->_174 = $this->_350 * $this->_663;
break;
case 1:
$this->_174 = $this->_822 << 8;
break;
}
$this->_858 = $this->_746 - $this->_174;
$this->_174 /= 32;
$this->_555();
$this->_888();
}
function _888()
{
$w = $this->_114 + $this->_822;
$h = $this->_115 + $this->_822;
$this->_988 = $w / 2;
$this->_445 = $h / 2;
$this->_999 = imageCreateTrueColor( $w, $h );
imageFill( $this->_999, 0, 0, imageColorAllocate( $this->_999, ( $this->_450 >> 16 ) & 0xFF, ( $this->_450 >> 8 ) & 0x00FF, $this->_450 & 0x0000FF ) );
$this->_266();
$this->_457();
}
function _266()
{
$this->_837();
$this->_377 += $this->_607;
if( $this->_377 > 0x16800 )
$this->_377 -= 0x16800;
$this->_531 += $this->_601;
if( $this->_531 > 0x16800 )
$this->_531 -= 0x16800;
$this->_571 += $this->_166;
if( $this->_571 > 0x16800 )
$this->_571 -= 0x16800;
$i = $this->_377 >> 8;
$l = $this->_531 >> 8;
$j1 = $this->_571 >> 8;
$l1 = ( $this->_925( $i ) * $this->_925( $j1 ) >> 8 ) + ( $this->_955( $i ) * $this->_955( $l ) * $this->_955( $j1 ) >> 16 );
$i2 = $this->_925( $l ) * $this->_955( $j1 ) >> 8;
$j2 = ( $this->_925( $i ) * $this->_955( $l ) * $this->_955( $j1 ) >> 16 ) - ( $this->_955( $i ) * $this->_925( $j1 ) >> 8 );
$k2 = ( $this->_955( $i ) * $this->_955( $l ) * $this->_925( $j1 ) >> 16 ) - ($this->_955( $j1 ) * $this->_925( $i ) >> 8 );
$l2 = $this->_925( $l ) * $this->_925($j1) >> 8;
$i3 = ( $this->_955( $i ) * $this->_955( $j1 ) >> 8 ) + ( $this->_925( $i ) * $this->_955( $l ) * $this->_925( $j1 ) >> 16 );
$j3 = $this->_955( $i ) * $this->_925( $l ) >> 8;
$k3 = -$this->_955( $l );
$l3 = $this->_925( $i ) * $this->_925( $l ) >> 8;
for( $j = 0; $j < $this->_563; $j++ )
{
$this->_014[ $j ] = $this->_147[ $j ] * $l1 + $this->_364[ $j ] * $i2 + $this->_091[ $j ] * $j2 >> 8;
$this->_303[ $j ] = $this->_147[ $j ] * $k2 + $this->_364[ $j ] * $l2 + $this->_091[ $j ] * $i3 >> 8;
$this->_513[ $j ] = ( $this->_147[ $j ] * $j3 + $this->_364[ $j ] * $k3 + $this->_091[ $j ] * $l3 >> 8 ) + $this->_746;
}
for( $k = 0; $k < $this->_563 - 1; $k++ )
{
for( $i1 = $k + 1; $i1 < $this->_563; $i1++ )
{
if( $this->_513[ $this->_165[ $i1 ] ] > $this->_513[ $this->_165[ $k ] ] )
{
$k1 = $this->_165[ $i1 ];
$this->_165[ $i1 ] = $this->_165[ $k ];
$this->_165[ $k ] = $k1;
}
}
}
}
function _837()
{
$l3 = 0;
$l7 = 0;
for( $l1 = 1; $l1 <= $this->_057[ 0 ]; $l1 += 2 )
{
$this->_364[ $l3 ] = $this->_057[ $l1 + 1 ] * $this->_350;
$this->_147[ $l3 ] = $this->_822 * $this->_955( $l7 + $this->_057[ $l1 ] * $this->_895 );
$this->_091[ $l3 ] = -$this->_822 * $this->_925( $l7 + $this->_057[ $l1 ] * $this->_895 );
$l3++;
}
$this->_563 = $l3;
for( $k3 = 0; $k3 < $this->_563; $k3++ )
$this->_165[ $k3 ] = $k3;
}
function _457()
{
for( $i1 = 0; $i1 < $this->_563; $i1++ )
{
$k = $this->_165[ $i1 ];
$l = $this->_710 / $this->_513[ $k ];
if( $l < 2 )
$l = 2;
$i = ( $this->_988 + ( $this->_014[ $k ] << 7 ) / $this->_513[ $k ] ) - ( $l >> 1 );
$j = ( $this->_445 + ( $this->_303[ $k ] << 7 ) / $this->_513[ $k ] ) - ( $l >> 1 );
$c = $this->_352[ ( $this->_513[ $k ] - $this->_858 ) / $this->_174 ];
imagefilledellipse( $this->_999, $i, $j, $l, $l, imageColorAllocate( $this->_999, ( $c >> 16 ) & 0xFF, ( $c >> 8 ) & 0x00FF, $c & 0x0000FF ) );
}
}
function _555()
{
$b1 = imageTTFBbox( $this->_112, 0, $this->_111, $this->_113 );
$b2 = $b1[ 4 ];
$b3 = abs( $b1[ 5 ] );
$im = imageCreateTrueColor( $b1[ 4] , abs( $b1[ 5 ] ) + 2 );
imageFill( $im, 0, 0, imageColorAllocate( $im, 255, 255, 255 ) );
imagettftext( $im, $this->_112, 0, 0, $b3, imageColorAllocate( $im, 0, 0, 0 ), $this->_111, $this->_113 );
$this->_114 = $x = imageSX( $im );
$this->_115 = $y = imageSY( $im );
$c = 0;
$q = 1;
$this->_057[ 0 ] = 0;
for( $i = 0; $i < $x; $i++ )
{
for( $j = 0; $j < $y; $j++ )
{
$p = imageColorsForIndex( $im, imageColorAt( $im, $i, $j ) );
if( $p[ 'red' ] < 128 && $p[ 'green' ] < 128 && $p[ 'blue' ] < 128 )
{
$this->_057[ $q ] = $i;
$this->_057[ $q + 1 ] = $j;
$q += 2;
$c += 2;
}
}
}
$this->_057[ 0 ] = $c;
$this->_435( $this->_116 );
}
function _435( $i )
{
for( $j = 2; $j <= $this->_057[ 0 ]; $j += 2 )
$this->_057[ $j ] -= $i;
}
function _955($i)
{
$j = $this->_726[ $i % 180 ];
if( $i > 180 )
$j *= -1;
return $j;
}
function _925( $i )
{
$j = $this->_726[ ( $i + 90 ) % 180 ];
if( $i > 90 && $i < 270 )
$j *= -1;
return $j;
}
function rgb2int( $rgb )
{
return $rgb[ r ] << 16 | $rgb[ g ] << 8 | $rgb[ b ];
}
function getImage()
{
return $this->_999;
}
}
/* EOF */
The example uses Gifmerge that helps create the GIF image which can be found here.
Quick documentation:PHP Code:set_time_limit( 0 );
header( 'Content-type: image/gif' );
require '3d ';
require 'GifMerge.class.php';
$j = 0;
$k = 0;
for( $i = 360; $i > 0; $i-- )
{
if( $j++ == 10 )
{
$3d = new 3d( 16, 96, 0, $i, 0, array( r => 22, g => 22, b => 22), array( r => 255, g => 255, b =>0 ), "fonts/arial.ttf", 16, "Exiled Hero is hawt!" );
ob_start();
imageGif( $3d->getImage() );
$frame[ $k ] = ob_get_contents();
$delay[ $k ] = 10;
ob_end_clean();
$j = 0;
$k++;
}
}
$anim = new GifMerge( $frame, 0, 0, 0, -10, $delay, 0, 0, 'C_MEMORY' );
echo $anim->getAnimation();
int distance can be used to change height distance between pixels.PHP Code:$3d = new text3d( int distance, int radius, int rotx, int roty, int rotz, array background color, array text color, string font, int fontsize, string text );
Distance to increase when this integer major and distance to decrease when this integer minor.
int radius can be used to change radius.
Radius to increase when this integer major and radius to decrease when this integer minor.
The rotx, roty, and rotz ints can be used to define the rotate angles.
Values of these integers keep from 0 to 360.
rotx can be used to define vertical rotate.
roty can be used to define horizontal rotate.
rotz can be used to define circle rotate.
array background and text colour parameters can be used to set the background and text color.
These parameters are array type and the values are decimal from 0 to 255.
PHP Code:array( r => 255, g => 255, b => 255 )



Reply With Quote


