Jump to content

Is it possible...


marcus

Recommended Posts

It will be another 20 minutes before I can get on my server that has the database, I'm doing a backup now so i don't want to login when it running. I will post the download after that...

Here is a simple example, you can use any image, the script uses an array() that sets the writing method (size, center, angles (hoz, vert)!

http://www.dinningoutoftown.com/test.php

example of the script!

[code]
<?
/* protect the include files */

define ( 'SYSTEM_REQUESTED', 1 );

/* the back end */

include_once ( '/home/vhost_27/no_access/ip/geo.php' );

/* begin the image display process */


// the image we are going to write to (must be a PNG)

$img = '/home/vhost_27/no_access/images/example.png';

// the write text array

/*
* see the example image * /geo/example.png * to understand each array value
top =>
array ( 0 => font size,
1 => the text write angle,
2 => text start vertical position
3 => text start writing position (from left edge of image)
4 => the font path and name
},
bottom =>
array ( 0 => font size,
1 => the text write angle,
2 => text start vertical position
3 => text start writing position (from left edge of image)
4 => the font path (full_path) and name
);
*
*/

$ta = array (
'top' => array ( 10, -10, 250, 0, '/home/vhost_27/no_access/fonts/arabolic.ttf' ),
'bottom' => array ( 10, -10, 270, 0, '/home/vhost_27/no_access/fonts/arabolic.ttf' )
);

// the top text

$top = 'I love';

// if a country name needs * the * before it we use this

/* ~ explained! (only used if no city is found and a country is found)
* countries that are a single word -> Canada, do not use $add
* countries that contain more than one word with a space -> United States, use $add
*/

$add = ' the';

// other result

/*
* when no city or country is found we use this
*/

$other = 'you';

// ending for the (bottom) line of text

$end = '!';


/* check for city, if we don't have one, check for a country */

if ( empty ( $data['city'] ) )
{
/* now check for a country, if no country we use $other */

if ( empty ( $data['country'] ) )
{
$text = $other . $end;
}
else
{
/* check if we need to add ($add) or strip (-) */

if ( str_word_count ( $data['country'] ) > 1 )
{
$top .= $add;
$text = $data['country'] . $end;
}
if ( strpos ( $data['country'], '-' ) !== false )
{
$text = str_replace ( '-', ' ', $data['country'] ) . $end;
}
else
{
$text = $data['country'] . $end;
}

}
}
else
{
$text = $data['city'] . $end;
}

/* load the image and set the text colors for writing */

$image = imagecreatefrompng ( $img );

//$backg = imagecolorallocate ( $image, 255, 255, 255 );

$color = imagecolorallocate ( $image, 131, 110, 92 );

/* get the exact position to write our (top) text */

  $center = imagettfbbox ( $ta['top'][0], $ta['top'][1], $ta['top'][4], $top );

$horzp = ( ( imagesx ( $image ) - abs ( $center[4] ) ) / 2 ) - $ta['top'][3];

/* write the (top) text */

imagettftext ( $image, $ta['top'][0], $ta['top'][1], $horzp, $ta['top'][2], $color, $ta['top'][4], $top );


/* get the exact position to write our (bottom) text */

  $center = imagettfbbox ( $ta['bottom'][0], $ta['bottom'][1], $ta['bottom'][4], $text );

$horzp = ( ( imagesx ( $image ) - abs ( $center[4] ) ) / 2 ) - $ta['bottom'][3];

/* write the (bottom) text */

imagettftext ( $image, $ta['bottom'][0], $ta['bottom'][1], $horzp, $ta['bottom'][2], $color, $ta['bottom'][4], $text );

/* write it out to the browser */

header ( 'Content-Type: image/jpeg;' );
imagejpeg ( $image );
imagedestroy ( $image );
?>
[/code]



me!
Link to comment
https://forums.phpfreaks.com/topic/23121-is-it-possible/#findComment-104689
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.