adding greek text watermark

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
grezi
Forum Newbie
Posts: 15
Joined: Tue Apr 03, 2007 5:25 am

adding greek text watermark

Post by grezi »

Hello every body, i have the following problem,
I am trying to write Greek text over image (with GD2 library and imagecreatefrompng gif or jpg ). I am recieving as a result strange character and seems that there is an encoding problem.
Is that possible?How ?
Thank you for your interest , any help would be appreciated
the code i use is something very simple

// load the image from the file specified:
$im = imagecreatefrompng("croc.png");

// if there's an error, stop processing the page:
if(!$im)
{
die("");
}

// define some colours to use with the image
$yellow = imagecolorallocate($im, 255, 255, 0);

$black = imagecolorallocate($im, 0, 0, 0);

// get the width and the height of the image
$width = imagesx($im);
$height = imagesy($im);

// draw a black rectangle across the bottom, say, 20 pixels of the image:
imagefilledrectangle($im, 0, ($height-20) , $width, $height, $black);

// now we want to write in the centre of the rectangle:
$font = 4; // store the int ID of the system font we're using in $font

$text = "mωδσδιφξσα"; // store the text we're going to write in $text

// calculate the left position of the text:
$leftTextPos = ( $width - imagefontwidth($font)*strlen($text) )/2;

// finally, write the string:
imagestring($im, $font, $leftTextPos, $height-18, $text, $yellow);

// output the image
// tell the browser what we're sending it
Header('Content-type: image/png');

// output the image as a png
imagepng($im);

// tidy up
imagedestroy($im);
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: adding greek text watermark

Post by onion2k »

The fonts built into GD2 are very basic, I very much doubt they include Greek characters. Either use imagettftext() or create your watermark as an image and use imagecopymerge().
grezi
Forum Newbie
Posts: 15
Joined: Tue Apr 03, 2007 5:25 am

Re: adding greek text watermark

Post by grezi »

Thank you so much! It is a font problem !
Post Reply