drawing on images with php

Need help with Photoshop, the GIMP, Illustrator, or others? Want to show off your work? Looking for advice on your newest Flash stuff?

Moderator: General Moderators

Post Reply
rapaddict_dot_com
Forum Commoner
Posts: 27
Joined: Tue Mar 16, 2004 4:54 pm

drawing on images with php

Post by rapaddict_dot_com »

I have a site where I want people to be able to make personal banners for there homepage

I want it to have 2 variables for the text

$text-name
and $text-desc

so it has the pre-selected banner and it adds text-name in big letters with customizable colors/fonts and the desc smaller

is there a way to do this?
rapaddict_dot_com
Forum Commoner
Posts: 27
Joined: Tue Mar 16, 2004 4:54 pm

Post by rapaddict_dot_com »

also i want it to save as $sess_user."_banner.jpeg"

and if that file already exists then I want it to delete it

does anyone know how to do all this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

read the [php_man]image[/php_man] function documentation.
rapaddict_dot_com
Forum Commoner
Posts: 27
Joined: Tue Mar 16, 2004 4:54 pm

Post by rapaddict_dot_com »

Code: Select all

<HTML><HEAD>
<TITLE>EZ Banner -- Online Banner Creator</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <meta name="keywords" PHP, Cynthia Porter, Banner Generator">
   <meta name="description" content="PHP Program to generate banners on-line.">
   <meta name="author" content="Cynthia Porter">
</HEAD>

<BODY bgColor=#ffffff vLink=#0000ff>
<DIV align=center>
<h1>EZ Banner Creator</h1>
<TABLE border=1>
   <TR>
   <TD bgColor=#99cc99>
   <FORM action=draw3.php>
   <P align=center>
      <TABLE border=1>
        <TR>
          <TD align=left><b>Banner Color</b></td>
          <TD align=middle><B>Line 1 Text Color</B></TD>
          <TD align=right><B>Line 2 Text Color</B></TD>
        </TR>
        <TR>
          <TD align=left>
          <B>R</B><INPUT name=r_b size=3 value=255 maxsize="3">
          <B>G</B><INPUT name=g_b size=3 value=000 maxsize="3">
          <B>B</B><INPUT name=b_b size=3 value=000 maxsize="3">
          </TD>
          <TD align=middle>
          <B>R</B><INPUT name=r_t1 size=3 value=000 maxsize="3">
          <B>G</B><INPUT name=g_t1 size=3 value=000 maxsize="3">
          <B>B</B><INPUT name=b_t1 size=3 value=000 maxsize="3">
          </TD>
          <TD align=right>
          <B>R</B><INPUT name=r_t2 size=3 value=255 maxsize="3">
          <B>G</B><INPUT name=g_t2 size=3 value=255 maxsize="3">
          <B>B</B><INPUT name=b_t2 size=3 value=255 maxsize="3">
          </TD>
        </TR>
        <TR>
          <TD align=middle colSpan=3><B>Text Line 1:</B><INPUT value="hoodz crew" name=string1 size=43 
            maxsize="80">   
          </td>
         </tr>
        <tr>
          <TD align=middle colSpan=3><B>Text Line 2:</B><INPUT value="illest in the game!" name=string2 size=43 
            maxsize="80">   
          </td>
        </tr>
        <TR>
          <TD align=middle>
          <INPUT type=submit value="Create Banner">
          <INPUT type=reset value=Reset>
          </td></tr>
          
          </TABLE>
      <p><b>Instructions:</B><br>
      <P>Choose your Background, Text Line 1, and Text Line 2 colors.
         Enter Text Line 1 and Text Line 2 as this will be the text that
         will be on your banner.  <br>
         Click the "Create Banner" button and your banner will appear at the
         bottom of this page along with its URL.  
         <br><br>

      <TABLE>
     
        <TR>
          <TD>
            <P><FONT size=-1>**Color is determined by the RedGreenBlue value. 
            To see the values of colors, go <A 
            href="http://www.websitetips.com/designer/colors2.html">here</A>
            to find your own colors then click your browser's back
            button to return to this page.
            </FONT></P></TD></TR></TABLE>
   </FORM>
    
<br>

</td></tr></table>
</DIV>

<center>
<br><br><br>

<? if ((isset($string1) || $string1 > "")
     and (isset($string2) || $string2 > "")) {

     chmod("banners", 0777);

$id = imagecreatefromjpeg("banners/1.jpg");

//$id = ImageCreate(460, 40);
//ImageFilledRectangle ($id, 0, 0, 460, 40, $bgc);


     $bgc = ImageColorAllocate($id, $r_b, $g_b, $b_b);
     $color1 = ImageColorAllocate($id, $r_t1, $g_t1, $b_t1);
     $color2 = ImageColorAllocate($id, $r_t2, $g_t2, $b_t2);
     ImageString($id, 5, 10, 2, $string1, $color1);
     ImageString($id, 5, 10, 20, $string2, $color2);
     $counterval = 0;
     $filename = "counter.txt";
     $fp = fopen($filename,"r"); 
     $counterval = fread($fp, 26 ); 
     fclose($fp); 
     $counterval = (integer)$counterval + 1; 
     $fp = fopen($filename,"w+"); 
     fwrite($fp, $counterval, 26); 
     fclose($fp );
     $newbanner = 'banners/' . $counterval . '.jpg';
     ImagePNG($id,$newbanner);
     $string1 = '';
     $string2 = '';
     echo '<img src=' . $newbanner . '><br>';
     echo '<a href=http://ezbanner.sourceforge.net/' . $newbanner . '>http://ezbanner.sourceforge.net/' . $newbanner . '</a>';
}

?>

</center>
<center>
<br><br>

</center>
</BODY></HTML>

^I got that code from a website.

How do I make it so the person can edit which font is being used? and so the colors on the form are RED GREEN BLUE instead of the hex codes.


feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Well.. it looks like the RGB values are already 0-255 fields... Next thing, that script was written with register_globals on.. for fonts, you'll have to enumerate the fonts you have available for them to use.
rapaddict_dot_com
Forum Commoner
Posts: 27
Joined: Tue Mar 16, 2004 4:54 pm

Post by rapaddict_dot_com »

and in english...?

hehe im a bit of a notice with the drawing thing...

is there an example I can see with a text-chooser?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

hmm.. you could search a certain folder for truetype fonts or whatever your version of FreeType supports... You could provide a simple list of them, or create an image based on each.. anything's fairly possible..
User avatar
m3mn0n
PHP Evangelist
Posts: 3547
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

RED in a form's drop down menu can be: 255-0-0
GREEN in a form's drop down menu can be: 0-255-0
BLUE in a form's drop down menu can be: 0-0-255

eg.

Code: Select all

&lt;option value="255-0-0"&gt;Red Font&lt;/option&gt;
Then on the form handling page, [php_man]explode[/php_man]() by "-" and you have an array of the hex values.

eg.

Code: Select all

<?php
$hex = explode ("-", $color);
?>
Post Reply