Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 20

Thread: PHP images

  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Posts
    216
    Thanks
    9
    Thanked 0 Times in 0 Posts

    PHP images

    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 Code:
    <?php

    $im 
    imagecreatefromgif('images/bar3d_08.gif');

    $bg imagecolorallocate($im255255255);
    $textcolor imagecolorallocate($im00255);


    imagestring($im10274"Hello world!"$textcolor);

    header("Content-type: image/png");

    $img imagepng($im);

    ?>

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Save that as another file, then call it using the html img

    <img src="image.php">

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,079
    Thanks
    2
    Thanked 320 Times in 312 Posts
    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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #4
    Regular Coder
    Join Date
    Sep 2006
    Posts
    216
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thank you, that works fine. But is there a way to change the font of the text over image??

    thanks

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    This is what I use for a captcha image I have
    PHP Code:
    <?php
    $string 
    'Some String';

    $captcha imagecreatefromjpeg("captcha.jpg");
    $black imagecolorallocate($captcha000);
    $line imagecolorallocate($captcha,233,239,239);
    imageline($captcha,0,0,39,29,$line);
    imageline($captcha,40,0,64,29,$line);
    imagestring($captcha5205$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
    Last edited by _Aerospace_Eng_; 07-22-2007 at 09:17 PM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #6
    Regular Coder
    Join Date
    Sep 2006
    Posts
    216
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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

  • #7
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    I'm guessing you didn't read the last link I posted.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #8
    Regular Coder
    Join Date
    Sep 2006
    Posts
    216
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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?

  • #9
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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);

  • #10
    Regular Coder
    Join Date
    Sep 2006
    Posts
    216
    Thanks
    9
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php

    $im 
    imagecreatefromgif('images/bar3d_08.gif');

    $bg imagecolorallocate($im255255255);
    $textcolor imagecolorallocate($im00255);


    $font imageloadfont('verdana.tff');

    //imagestring($im, $font, 27, 4, 'hello World', $textcolor);

    ImageTTFText($im20274$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

  • #11
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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
    Attached Files Attached Files
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #12
    Regular Coder
    Join Date
    Jul 2007
    Location
    Scotland
    Posts
    134
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Download Button

    Sorry wrong section.
    Last edited by graham23s; 07-23-2007 at 10:16 PM.

  • #13
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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.

  • #14
    Regular Coder
    Join Date
    Sep 2006
    Posts
    216
    Thanks
    9
    Thanked 0 Times in 0 Posts
    [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??

  • #15
    Regular Coder
    Join Date
    Sep 2006
    Posts
    216
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •