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.
Results 1 to 6 of 6

Thread: functions use

  1. #1
    New Coder
    Join Date
    Jul 2003
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    image creation

    i was wonder of creation a function that creates images with different text dependant on its argument:

    PHP Code:
    function image_create($string){ 
        
    header("Content-type: image/png"); 
        
    $im     imagecreatefrompng("button.png"); 
        
    $colour imagecolorallocate($im100100100); 
        
    $px     = (imagesx($im) - 7.5 strlen($string)) / 2
        
    imagestring($im3$px4$string$colour); 
        
    imagepng($im); 
        
    imagedestroy($im); 
        } 

    echo  
    image_create("home"); 
    echo  
    image_create("info"); 
    echo  
    image_create("media"); 
    it produces only home image.
    where is the fault?
    Last edited by romalong; 06-07-2004 at 11:08 PM.

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,047
    Thanks
    10
    Thanked 93 Times in 91 Posts
    there is no fault , but you can only display 1 image at a time in this manner (setting the content type header) , save your images to file individually , then display them via <img src="" etc
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New Coder
    Join Date
    Jul 2003
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by firepages
    there is no fault , but you can only display 1 image at a time in this manner (setting the content type header) , save your images to file individually , then display them via <img src="" etc

    it's too simple to use common HTML.
    i'm learning graphic support in PHP and hope it's possible to create such function, at least i'll try...

  • #4
    New Coder
    Join Date
    Jul 2003
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts
    are there any other way to create images via PHP?
    i tried to screw it up, but nothing happen - only one image dysplays at a time...
    Last edited by romalong; 06-07-2004 at 04:06 PM.

  • #5
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,047
    Thanks
    10
    Thanked 93 Times in 91 Posts
    if you add a filename PHP creates the image file for you..(so in your code this will create all 3 images for you (drop the header() call)

    imagepng( $im , $string.'.png' ) ;


    but you still can only display 1 image at a time in the browser unless you

    echo '<img src="'.$string.'.png" />';

    you could create a composite image of the 3 images if you wanted (e.g. 1 image)
    another popular library often used with PHP for images is imagemagick
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #6
    New Coder
    Join Date
    Jul 2003
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts
    cheers firepages!

    it works:

    PHP Code:

        $menu 
    = array(home,downloads,chat,media,forum,contact);

        foreach (
    $menu as $value){

           
    $im     imagecreatefrompng("button.png");
           
    $colour imagecolorallocate($im100100100);
           
    $px     = (imagesx($im) - 6.5 strlen($value)) / 2;
           
    imagestring($im3$px4$value$colour);
           
    imagepng($im,$value.'.png');
           
    imagedestroy($im);
           echo 
    '<a href="'.$value.'.php"><img src="'.$value.'.png" border="0" alt="'.$value.'" /></a>'."\n";

                } 


  •  

    Posting Permissions

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