alex57 07-22-2007, 10:51 AM Hello, this is code to display text horizontally on top of the image 'bar3d_08.gif' which does work. However, this code needs to go at the top of the page otherwise a heaers not sent error appears which is fine. However, if the code is placed there, nothing else on the page is rendered, the page only displays this button with the text on it. Why is nothing else rendering. It is annoying as this gif is part of a bigger image.
Thanks in advance
<?php
$im = imagecreatefromgif('images/bar3d_08.gif');
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);
imagestring($im, 10, 27, 4, "Hello world!", $textcolor);
header("Content-type: image/png");
$img = imagepng($im);
?>
Nightfire 07-22-2007, 11:03 AM Save that as another file, then call it using the html img
<img src="image.php">
CFMaBiSmAd 07-22-2007, 11:06 AM Edit: Basically says the same as above ^^ (took me a while to find and copy/paste from the last time I posted it)
The only way to place an image on a web page and get a browser to render it is to use an <img src="a_url_that_outputs_an_image" alt=""> tag - http://w3schools.com/html/html_images.asp This is the only thing browsers understand. You need one <img...> tag for each image. The a_url_that_outputs_an_image needs to be to a separate .php file with your header/image echo output code in it.
alex57 07-22-2007, 07:09 PM Thank you, that works fine. But is there a way to change the font of the text over image??
thanks
_Aerospace_Eng_ 07-22-2007, 09:12 PM This is what I use for a captcha image I have
<?php
$string = 'Some String';
$captcha = imagecreatefromjpeg("captcha.jpg");
$black = imagecolorallocate($captcha, 0, 0, 0);
$line = imagecolorallocate($captcha,233,239,239);
imageline($captcha,0,0,39,29,$line);
imageline($captcha,40,0,64,29,$line);
imagestring($captcha, 5, 20, 5, $string, $black);
header("Content-type: image/jpeg");
imagejpeg($captcha);
?>
I think you want the imagestring function. It has a preset number fonts you could use, these are the common ones like verdana, and arial. You can also load a new font using the imageloadfont method.
http://us.php.net/manual/en/function.imageloadfont.php
alex57 07-23-2007, 07:11 PM Hello,
I am using the imagestring() function and i realise that the second parameter is the font number. However it only accepts the values 1 -5 which only makes the same font larger or smaller. How can I change the font altogether??
thanks
_Aerospace_Eng_ 07-23-2007, 07:21 PM I'm guessing you didn't read the last link I posted.
alex57 07-23-2007, 08:10 PM I did follow the link but the preset fonts eg Verdana would be fine. How do I access the preset fonts or am I misunderstanding what you are saying?
mlseim 07-23-2007, 08:32 PM Upload the .ttf file you want to use into the same directory,
then do something like this:
$font = "ConvectionRegular.ttf";
$fontSize = "28";
$fontRotation = "0";
$string="This your text ...";
...blah blah ... more code
ImageTTFText($iBackground, $fontSize, $fontRotation, $fposx, $fposy, $color, $font, $string);
alex57 07-23-2007, 09:56 PM <?php
$im = imagecreatefromgif('images/bar3d_08.gif');
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);
$font = imageloadfont('verdana.tff');
//imagestring($im, $font, 27, 4, 'hello World', $textcolor);
ImageTTFText($im, 2, 0, 27, 4, $textcolor, $font, 'hello world');
header("Content-type: image/png");
imagepng($im);
?>
That is now my code. Produces errors assocaited with the font. I located the verdana.tff file in my C:\WINDOWS directory and copied to server in the same directory as the php page running the script. Errors I get are:
Warning: imageloadfont(/verdana.tff) [function.imageloadfont]: failed to open stream: No such file or directory in C:\Program Files\xampp\htdocs\trip2\location.php on line 9
Warning: imagettftext() [function.imagettftext]: Could not find/open font in C:\Program Files\xampp\htdocs\trip2\location.php on line 13
this looks like the location is incorrect but the .tff and the sript are in the same file so the code is right. What else am I doing wrong??
Thanks
_Aerospace_Eng_ 07-23-2007, 10:03 PM I think you have to convert the font some how. The lastest note posted by dave [at] wedwick.com posts a url to a program that converts windows fonts to .gdf format. I've downloaded the converter and scanned it for viruses. Its clean. Attached is the verdana windows font converted to .gdf format.
Read mlseim's last post. I think its more of what you want.
With imageloadfont you use imagestring instead. To use the .tff font format then all you need is to set the location of the file file and you can use ImageTFFText
graham23s 07-23-2007, 10:13 PM Sorry wrong section.
mlseim 07-23-2007, 11:22 PM Look at your error messages:
C:\Program Files\xampp\htdocs\trip2\location
On your website (your files in your webhost's server) I'm guessing
that is not the correct path. It looks like a path on your own PC.
alex57 07-23-2007, 11:25 PM [PHP]<?php
$im = imagecreatefromgif('images/bar3d_08.gif');
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);
$font = imageloadfont('verdana.gdf');
imagestring($im, $font, 27, 4, 'hello World', $textcolor);
//ImageTTFText($im, 1, 0, 3, 4, $textcolor, $font, 'hello world');
header("Content-type: image/png");
imagepng($im);
?> /PHP]
I am using the imagestring in conjunction with the imageloadfont() function but this didnt change the font of the text string any more ideas??
alex57 07-23-2007, 11:28 PM In reply to mlseim it is the path on my computer as im developing the webpage on my local machine (apache webserver). But the locations are all correct
Len Whistler 07-23-2007, 11:40 PM Change:
$font = imageloadfont('verdana.gdf');
To:
$font = 'verdana.ttf';
alex57 07-24-2007, 10:32 AM That did not work either. Is there something wrong with the script because neither imageloadfont('verdana.ttf') or imageloadfont('verdana.gdf') work
_Aerospace_Eng_ 07-24-2007, 10:43 AM I just read this thread which recently was revived and it appears that the absolute path to the font file is required.
http://www.codingforums.com/showthread.php?t=83032
CFMaBiSmAd 07-24-2007, 05:25 PM This must be an "other than Windows" problem this time, because I was able to get the similar code in the PHP manual to work with your font file in the same folder as the script file, just using a relative path.
For the current problem, the imageloadfont(...) function call might be failing and returning a FALSE value, which seemed to result in the same results as using the '1' font value for the testing I just did.
The PHP manual also states that the format of the .gdf file is CPU dependent. This might or might not have anything to do with the current problem (aren't we all using Intel processors now days?)
Len Whistler 07-24-2007, 06:03 PM That did not work either. Is there something wrong with the script because neither imageloadfont('verdana.ttf') or imageloadfont('verdana.gdf') work
I would completely eliminate imageloadfont. Below is the working code I use, the font is in the same directory as the script. Just make sure that it's all in lower case or upper case. Absolute path to the font file is not required.
$font = 'verdana.ttf';
|
|