Thread: Create image

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    6
    Rep Power
    0

    Create image


    Hi guys, i have problem with php. I want to make website which create baner for user when they fill out the form. This is banner (without text and image):

    misterijeforum.com/nik/images/medium.png

    I made form also. link: misterijeforum.com/nik/small.html
    But i got problems with php script. I'm not php programmer, but i created "something" []

    PHP Code:
    <?php
    header
    ('Content-Type: image/png');

    $im ImageCreateFromPng("images/medium.png"); 

    $black imagecolorallocate($im000);
    $ime "$fullname";
    $interests "%interests";
    $school "%school";
    $fb "%facebook";
    $msn "%msn";
    $mail "%mail";
    $start_x 1;
    $start_y 1;
    Imagettftext($im120$start_x$start_y$black'verdana.ttf'$ime);

    Imagepng($im);

    ImageDestroy($im);


    ?>
    I made just for full name, but i don't know how to storage that new image in folder "images" and show image to user. And is this code good ?
  2. #2
  3. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
    Is that the actual code you have? There's a few big and obvious problems with it, like using "%interests" and that you only call imagettftext() for the $ime.

    As to your question, imagepng() can take a filename to save to as its second argument. Make sure your images folder has permissions 0777 (which you can set with FTP or probably whatever file browsing tool you have available).
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by requinix
    Is that the actual code you have? There's a few big and obvious problems with it, like using "%interests" and that you only call imagettftext() for the $ime.

    As to your question, imagepng() can take a filename to save to as its second argument. Make sure your images folder has permissions 0777 (which you can set with FTP or probably whatever file browsing tool you have available).
    Huh, that code is **** I just found it on internet and modified it. Can you explain me how to do that or better to give me code. So i want to, when user fill out the form and click on "submit", it generate benner with informations which user write in form and that picture/banner storage in folder "images". Backgroud of banner will be misterijeforum.com/nik/images/medium.png . Thank you so much
  6. #4
  7. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
    I can't write it for you but that should be okay as what you have now is a decent enough start. The script to generate the image (and not display it) goes like this:
    Code:
    imagecreatefrompng() the original "template" image you want
    
    pick a color for the text
    imagettftext() all the different strings onto the image, at the right location, using the text color
    // you'll have to play around with the text offset until you get it in the right place
    // text length is a concern...
    
    imagepng() the image to the final destination
    imagedestroy() the image
    - Question: what if someone enters a really long name? How do you want to deal with the fact that it would run off the image?
    - You should put this in a function with parameters for the different pieces of information as well as the place where the new image should be saved
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by requinix
    I can't write it for you but that should be okay as what you have now is a decent enough start. The script to generate the image (and not display it) goes like this:
    Code:
    imagecreatefrompng() the original "template" image you want
    
    pick a color for the text
    imagettftext() all the different strings onto the image, at the right location, using the text color
    // you'll have to play around with the text offset until you get it in the right place
    // text length is a concern...
    
    imagepng() the image to the final destination
    imagedestroy() the image
    - Question: what if someone enters a really long name? How do you want to deal with the fact that it would run off the image?
    - You should put this in a function with parameters for the different pieces of information as well as the place where the new image should be saved
    PHP Code:
    <?php 
    header
    ('Content-Type: image/png'); 
    $im imagecreatefrompng("medium.png");
    $textcolor imagecolorexact($im255255255); 
    imagefttext($im10055$textcolor"C:/WINDOWS/Fonts/tahoma.ttf""Some text"); 
    Imagepng($im); 
    ImageDestroy($im);  
    ?>
    I think it's ok for now. How to put now generated image to folder "banners" (example) as .png file and display it?

    -Well, i want first to make it works, details later
  10. #6
  11. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
    When posting code, paste your code into the textbox, select it, and then hit the PHP code button. If you paste it into that dialog then all the line breaks disappear and the result is totally unreadable.

    Like I said earlier, if you want to save the image somewhere then pass a filename to imagepng(). Read the documentation if you're not sure what I mean.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    6
    Rep Power
    0
    Fixed. Ok i must go to sleep now, i will post tomorrow. Thanks for help.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    6
    Rep Power
    0
    Problems again I really don't know what to do, everything i try to do, when i run script it's showing: i.imgur.com/C7uvgly.png . Now i have this code:

    PHP Code:
    <?php

    header
    ('Content-Type: image/png'); 
    $im imagecreatefrompng("medium.png");
    $textcolor imagecolorexact($im255255255); 
    imagefttext($im10055$textcolor"tahoma.ttf""Some text"); 
    $save "../sigs/"time() .".png";
    imagepng($im$save);
    imagedestroy($im);

    ?>
    Please help me.
  16. #9
  17. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
    Please don't link me to imgur, I need to get some work done today

    Your call to imagepng() will only save the image. It will not output it as well.

    In general when you see the "the image cannot be displayed" error, remove any header() you might have that changes the Content-Type and refresh: there's typically an error message somewhere.

    Comments on this post

    • n1kol4n1k agrees : I know i don't have rep. points, but thank you very much :)
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by requinix
    Your call to imagepng() will only save the image. It will not output it as well.
    How to do that? Sorry for stupid questions i'm beginner. And when i remove header() function, it's show 2 errors, first:
    -Could not find/open font- But i put tahoma.ttf .
    - Unable to open '../sigs/1362094888.png' for writing- i suppose that is what you are talking about output.
  20. #11
  21. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
    Originally Posted by n1kol4n1k
    -Could not find/open font- But i put tahoma.ttf .
    Did you give the right path to it? What happened to the C:\Windows\Fonts you had before?
    Originally Posted by n1kol4n1k
    - Unable to open '../sigs/1362094888.png' for writing- i suppose that is what you are talking about output.
    That's a common issue. Depending how PHP is running it may or may not have permission to create files and folders. Are you using IIS?

IMN logo majestic logo threadwatch logo seochat tools logo