PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 27th, 2013, 04:05 PM
n1kol4n1k n1kol4n1k is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 6 n1kol4n1k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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" []

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 ?

Reply With Quote
  #2  
Old February 27th, 2013, 04:36 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,714 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 7 h 6 m 6 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to 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).

Reply With Quote
  #3  
Old February 27th, 2013, 05:01 PM
n1kol4n1k n1kol4n1k is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 6 n1kol4n1k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #4  
Old February 27th, 2013, 06:15 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,714 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 7 h 6 m 6 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to 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

Reply With Quote
  #5  
Old February 27th, 2013, 07:30 PM
n1kol4n1k n1kol4n1k is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 6 n1kol4n1k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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


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

Reply With Quote
  #6  
Old February 27th, 2013, 07:33 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,714 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 7 h 6 m 6 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
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.

Reply With Quote
  #7  
Old February 27th, 2013, 07:47 PM
n1kol4n1k n1kol4n1k is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 6 n1kol4n1k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 9 m 25 sec
Reputation Power: 0
Fixed. Ok i must go to sleep now, i will post tomorrow. Thanks for help.

Reply With Quote
  #8  
Old February 28th, 2013, 03:40 PM
n1kol4n1k n1kol4n1k is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 6 n1kol4n1k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 9 m 25 sec
Reputation 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.

Reply With Quote
  #9  
Old February 28th, 2013, 04:06 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,714 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 7 h 6 m 6 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
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

Reply With Quote
  #10  
Old February 28th, 2013, 05:52 PM
n1kol4n1k n1kol4n1k is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 6 n1kol4n1k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #11  
Old February 28th, 2013, 06:13 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,714 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 7 h 6 m 6 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Quote:
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?
Quote:
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?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-DB - Create image

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap