Where we bring you our picks for the year that was, including our Game of the Year.
AusGamers' Games of 2017
Where fights aren't split over a dozen 22 minute episodes.
Dragon Ball FighterZ Open Beta Impressions
We review the entire three-episode prequel series. Spoiler alert - it's great!
Life is Strange: Before the Storm Review
php & dynamic images through a form
Morax
Brisbane, Queensland
1969 posts
Hey all,

I figured this would be a good place to ask.. I have a friend who I am making a website for, and he requires something which I've never done. He has a number of products where the customer can customize what is written on a tag, and he needs the tag to update on the fly (image preview) when the user enters the text in a text field.

For those who have a bit of experience with dynamic forms, am I right in thinking to look at how captcha images are made and work from there?

Any help on where to start would be appreciated!

PS. I can read/write code, just not sure where to start
06:27pm 30/04/10 Permalink
system
Internet
--
06:27pm 30/04/10 Permalink
thermite
Brisbane, Queensland
5059 posts
Rip this drupal module off:
http://drupal.org/project/textimage

It uses GD2 and freetype:
http://php.net/manual/en/book.image.php
http://freetype.sourceforge.net/index2.html (?)

might also be useful
http://www.imagemagick.org/script/index.php

You could also do a low-tech version by simply putting a background image behind some text. Only need some CSS/HTML skills for that.



last edited by thermite at 18:44:19 30/Apr/10
06:42pm 30/04/10 Permalink
tequila
Brisbane, Queensland
7023 posts
This is something I knocked up years ago, very basic but it gives you an idea of where to start
see it in action here: http://unix.org.au/~brett/licence/


include('duration.lib.php');
//$args = $_SERVER['argv'];
$args = $_GET['month'].$_GET['day'].$_GET['year'];
$ctime = (mktime(0,0,0,$_GET['month'],$_GET['day'],$_GET['year']) - time());
$_GET['text'] = str_replace("\\","",stripslashes($_GET['text']));
$text = $_GET['text']." ".duration($ctime)."\n";


function draw_opaque($text) {
//$h = 200;
$h = 10;
$w = 1000;
$size = imageTTFBBox($h, 0, "/home/brett/public_html/licence/arial.ttf", $text);
//$size = imageTTFBBox($h, 0, "/usr/share/fonts/truetype/fifthhorseman/dkg.ttf", $text);
$image = imageCreateTrueColor(abs($size[2]) + abs($size[0]), abs($size[7]) + abs($size[1]));
imageSaveAlpha($image, true);
ImageAlphaBlending($image, false);

$tlo = imagecolorallocatealpha($image, 120, 120, 120, 127);
imagefill($image, 0, 0, $tlo);

$napis = imagecolorallocate($image, 120, 120, 120);
imagettftext($image, $h, 0, 0, abs($size[5]), $napis, "/home/brett/public_html/licence/arial.ttf", $text);
//imagettftext($image, $h, 0, 0, abs($size[5]), $napis, "/usr/share/fonts/truetype/fifthhorseman/dkg.ttf", $text);
return imagepng($image);
imagedestroy($image);
}
if ($text) {
header("Content-type: image/png");
draw_opaque($text);
}




----


duration.php

function duration($timestamp) {

$years=floor($timestamp / (60*60*24*365));
$timestamp%=60*60*24*365;

$weeks=floor($timestamp / (60*60*24*7));
$timestamp%=60*60*24*7;

$days=floor($timestamp / (60*60*24));
$timestamp%=60*60*24;

$hrs=floor($timestamp / (60*60));
$timestamp%=60*60;

$mins=floor($timestamp / 60);
$secs=$timestamp % 60;

$str="";

if ($years >= 1) { $str.="{$years} years "; }
if ($months >=1) { $str.="{$months} months "; }
if ($weeks >= 1) {
if ($weeks == 1) { $weekq="week"; } else { $weekq="weeks"; }
$str.="{$weeks} ".$weekq." ";
}
if ($days >= 1) { $str.="{$days} days "; }
if ($hrs >= 1) { $str.="{$hrs} hours "; }
if ($mins >= 1) { $str.="{$mins} minutes "; }
if ($secs >= 1) { $str.="{$secs} seconds "; }

return $str;
}

07:18pm 30/04/10 Permalink
system
Internet
--
07:18pm 30/04/10 Permalink
AusGamers Forums
Show: per page
1
This thread is archived and cannot be replied to.