Jump to content


Photo

Image creation/text addition help


  • Please log in to reply
5 replies to this topic

#1 DaveLinger

DaveLinger
  • Members
  • PipPipPip
  • Advanced Member
  • 268 posts
  • LocationWV, USA

Posted 20 July 2006 - 03:36 PM

<?php

$template = $_GET['template'];

$nametext = $_GET['nametext'];
$namefont = $_GET['namefont'];
$namecolor = $_GET['namecolor'];

$subtitle = $_GET['subtitle'];
$subfont = $_GET['subfont'];
$subcolor = $_GET['subcolor'];

// Set the content-type
header("Content-type: image/png");

// Create the image
$im = imagecreatefrompng('$template');

// Create some colors
switch ($namecolor)
{
  case "black":
    $ncolor = imagecolorallocate($im, 0, 0, 0);
    break;
	case "white":
    $ncolor = imagecolorallocate($im, 255, 255, 255);
    break;
}

switch ($subcolor)
{
  case "black":
    $scolor = imagecolorallocate($im, 0, 0, 0);
    break;
	case "white":
    $scolor = imagecolorallocate($im, 255, 255, 255);
    break;
}

// Add the text
imagettftext($im, 20, 0, 23, 20, $ncolor, $namefont, $nametext);
imagettftext($im, 12, 0, 23, 120, $scolor, $subfont, $subtitle);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

yields "The image “http://www.davessonicsite.com/sig/signature.php?template=shadow1.png&nametext=[PCR]Davers&namefont=Verdana.ttf&namecolor=black&subtitle=I%20pwn%20n00bs&subfont=Verdana.ttf&subcolor=black” cannot be displayed, because it contains errors."

shadow1.png and Verdana.ttf are in the same folder as signature.php... any ideas?
http://www.DaveLinger.com
dave at linger dot com

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 20 July 2006 - 03:56 PM

<?php
$im = imagecreatefrompng('$template');
//Change to...
$im = imagecreatefrompng($template);
//Or...
$im = imagecreatefrompng("$template");
//Because...
$foo = "bar";
echo $foo;   //Displays "bar"
echo "$foo"; //Displays "bar"
echo '$foo'; //Displays "$foo"
?>


#3 DaveLinger

DaveLinger
  • Members
  • PipPipPip
  • Advanced Member
  • 268 posts
  • LocationWV, USA

Posted 20 July 2006 - 04:00 PM

wow. I've been coding PHP for years now and I never realized that single quotes echo the name of the variable. dang.

Thanks!
http://www.DaveLinger.com
dave at linger dot com

#4 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 20 July 2006 - 04:01 PM

No problem :)

#5 DaveLinger

DaveLinger
  • Members
  • PipPipPip
  • Advanced Member
  • 268 posts
  • LocationWV, USA

Posted 20 July 2006 - 04:03 PM

one last question (for now :P)

the x aligning of the text is correct but my "name" is all the way at the top!

http://www.davessoni...g/imagetest.htm

and my code says the name text should start at 23,20 not 23,0!
http://www.DaveLinger.com
dave at linger dot com

#6 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 20 July 2006 - 04:09 PM

The x and y coordinates define the basepoint of the first character (roughly the lower-left corner of the character). Not the top left.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users