Discuss Create image in the PHP Development forum on Dev Shed. Create image PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
Posts: 6
Time spent in forums: 1 h 9 m 25 sec
Reputation Power: 0
PHP-DB - 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" []
Posts: 12,714
Time spent in forums: 5 Months 1 Week 4 Days 7 h 6 m 6 sec
Reputation Power: 8969
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).
Posts: 6
Time spent in forums: 1 h 9 m 25 sec
Reputation Power: 0
Quote:
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
Posts: 12,714
Time spent in forums: 5 Months 1 Week 4 Days 7 h 6 m 6 sec
Reputation Power: 8969
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
Posts: 6
Time spent in forums: 1 h 9 m 25 sec
Reputation Power: 0
Quote:
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
Posts: 12,714
Time spent in forums: 5 Months 1 Week 4 Days 7 h 6 m 6 sec
Reputation Power: 8969
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.
Posts: 12,714
Time spent in forums: 5 Months 1 Week 4 Days 7 h 6 m 6 sec
Reputation Power: 8969
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.
Posts: 6
Time spent in forums: 1 h 9 m 25 sec
Reputation Power: 0
Quote:
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.