SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Evangelist cturner01's Avatar
    Join Date
    Jun 2006
    Location
    My computer
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating images question

    I am wondering if someone could please tell me how I could create an image exactly like the attached one using PHP? Also I would like the image to be saved to the server. Thanks in advance.
    Attached Images Attached Images

  2. #2
    SitePoint Zealot Dachande663's Avatar
    Join Date
    Feb 2005
    Location
    Birmingham, UK
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    While waiting for the image to be approved, you will most probably have to use some form of th GD library, check out http://php.net/gd
    Web Developer & Geek: hybridlogic.co.uk ~ lukelanchester.com

  3. #3
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Using GD's own font selection:
    PHP Code:
    <?php
    header
    ("Content-type: image/png");
    $im = @imagecreate(20023)
        or die(
    "Cannot Initialize new GD image stream");
    $background_color imagecolorallocate($im057122);
    $text_color imagecolorallocate($im255255255);
    imagestring($im3105,  "ABOUT US"$text_color);
    imagepng($im);
    imagedestroy($im);
    ?>
    gives the following



    play with the imagestring fonts and also look into imagettftext() for antialiased text.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  4. #4
    SitePoint Addict pkSML's Avatar
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    230
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To save the image to the server, modify the imagepng function.

    PHP Code:
    imagepng ($im"/pics/image.png"
    -Stephen

    Get a LitlURL to this page!

  5. #5
    SitePoint Evangelist cturner01's Avatar
    Join Date
    Jun 2006
    Location
    My computer
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys, you have been great. But what happens if I don't want to save the image as a png. I would prefer it to be saved as a gif or jpeg. My GD version is 2.0.28, if that helps.

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Change the header to:
    PHP Code:
    header("Content-type: image/jpeg"); 
    and the line:
    imagepng ($im, "/pics/image.png")
    PHP Code:
    imagejpeg ($im"/pics/image.jpg"
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  7. #7
    SitePoint Evangelist cturner01's Avatar
    Join Date
    Jun 2006
    Location
    My computer
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am now getting the following error:
    <b>Warning</b>: imagejpeg() [<a href='function.imagejpeg'>function.imagejpeg</a>]: Unable to open '/images/aboutusbtn.jpeg' for writing in <b>/home/account/public_html/folder/createimage.php</b> on line <b>10</b><br />. Can someone please help me solve this error?

  8. #8
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Post your code please
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  9. #9
    SitePoint Evangelist cturner01's Avatar
    Join Date
    Jun 2006
    Location
    My computer
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code PHP:
    ob_start();
    header("Content-type: image/jpeg"); 
    $im = @imagecreate(200, 23)
    or die("Cannot Initialize new GD image stream");
    $background_color = imagecolorallocate($im, 0, 57, 122);
    $text_color = imagecolorallocate($im, 255, 255, 255);
    imagestring($im, 3, 10, 5,  "ABOUT US", $text_color);
     
    imagejpeg ($im, "/images/aboutusbtn.jpeg"); // line 10 is here
     
    imagedestroy($im);
    ob_end_flush();

  10. #10
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    OK, using that code it works fine for me. The only thing I changed was the path it was saving to; I removed the /images/ and ran the code.

    Check that the folder has write permissions and also - is this going to be used repeatedly for creating buttons on the fly? If so I would consider putting it into a function rather than call it through the browser.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  11. #11
    SitePoint Evangelist cturner01's Avatar
    Join Date
    Jun 2006
    Location
    My computer
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have made more changes to the code and now it isn't displaying the text on the button. Also it is only saving it as .jpeg. Thanks in advance.

    Code PHP:
    			function makeimage() {
    				$button = str_replace(' ', '', $pagetitle);
    				header("Content-type: image/jpeg"); 
    				$im = @imagecreate(200, 23)
    				or die("Cannot Initialize new GD image stream.");
    				$background_color = imagecolorallocate($im, 0, 57, 122);
    				$text_color = imagecolorallocate($im, 255, 255, 255);
    				imagestring($im, 3, 10, 5,  $button, $text_color);
    				$button2 = imagejpeg ($im, $button.".jpeg");
    				imagedestroy($im);
    			}
    			makeimage();


Bookmarks

Posting Permissions

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