Jump to content

Archived

This topic is now archived and is closed to further replies.

DaveLinger

Image creation/text addition help

Recommended Posts

[code]<?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);
?>[/code]

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?

Share this post


Link to post
Share on other sites
[code]<?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"
?>[/code]

Share this post


Link to post
Share on other sites
wow. I've been coding PHP for years now and I never realized that single quotes echo the name of the variable. dang.

Thanks!

Share this post


Link to post
Share on other sites
No problem :)

Share this post


Link to post
Share on other sites
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.davessonicsite.com/sig/imagetest.htm

and my code says the name text should start at 23,20 not 23,0!

Share this post


Link to post
Share on other sites
The x and y coordinates define the basepoint of the first character (roughly the lower-left corner of the character). Not the top left.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.