View Full Version : Is this Possible?
sidorak95
09-10-2008, 04:27 PM
I was wondering if this was possible and if it was, what programming language I would need. Would it be possible to have a number in a picture that changes to the next digit if someone clicks on something? Thanks!
sjlplat
09-10-2008, 05:26 PM
Yes, it is possible. You will need a client-side scripting language. Javascript, AJAX, and Flash can all do this.
sidorak95
09-10-2008, 06:36 PM
Any pointer on where to start? Thanks!
sjlplat
09-12-2008, 08:04 AM
You might consider a combination of Javascript and CSS to achieve what you're looking for. I've used the CSS z-index selector in the past to create a DIV overlay. You might create a DIV overlay placed on top of your image, and then use a Javascript string-changing script inside the DIV overlay.
sidorak95
09-12-2008, 11:38 AM
Would it be possible if the text was actually in the image?
pghcollectibles
09-12-2008, 12:14 PM
this would be easy to do using php gd commands.
if this code was in a file named number.php:
<?php
$im = imagecreate(10, 10);
$number=filter_input(INPUT_GET, 'number', FILTER_SANITIZE_ENCODED);
if ($number=""){$number="0";}
$bg = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
// prints first characture of $number or a 0
imagechar($im, 1, 0, 0, $number, $black);
header('Content-type: image/png');
imagepng($im);
?>
(edited from source php.net (http://us.php.net/manual/en/function.imagechar.php))
wherever you wanted the picture you would place this code:
<?php
$number=filter_input(INPUT_GET, 'number', FILTER_SANITIZE_ENCODED);
$pagenumber=$number + 1; // whatever math you want
?>
<a href='thispage.php?number=<?php echo $pagenumber; ?>' target='_top'>
<img src='number.php?number=<?php echo $number; ?>' border='0' />
</a>
theres more to edit but ive been busy lately and if you want more input just ask
sidorak95
09-12-2008, 01:45 PM
Sorry, I have no clue what to replace.
pghcollectibles
09-12-2008, 10:04 PM
what will they be clicking on and what do you want the number to do? up/down buttons? what is the purpose of this? not that there has to be one, i was just asking. as i learn more and more about php i have started to go through php.net and just duplicate examples and see what happens
the captcha stuff led me to make this (http://www.pghcollectibles.com/downloads/phpimage/font/test03.php) a while ago. i havent made numbers yet but this is a little more exotic than what it sounds like you are talking about. but imagechar() seems to be what you would want
sjlplat
09-13-2008, 08:12 AM
Yes, GD can add text to existing image files. If you want the image to refresh without refreshing the page, you will need to use Javascript to call the PHP-based image generator to change the text. It's usually easiest to use a True Type Font file to format your characters, so the first place to start would be to select a font that you want to use.
pghcollectibles
09-13-2008, 11:39 AM
ok i tested this here (http://www.pghcollectibles.com/downloads/phpimage/font/test06.php).
this is image code, file to be named number.php:
<?php
$im = imagecreate(10, 20);//this is the size of the picture width,height
$var=$_GET["number"];
$int_options = array("options"=>array("min_range"=>0, "max_range"=>9));
$number=filter_var($var, FILTER_VALIDATE_INT, $int_options);
if (!$number || $number==""){$number="0";}
$bg = imagecolorallocate($im, 255, 255, 255); //edit numbers to change background color
$black = imagecolorallocate($im, 0, 0, 0);//edit numbers to change font color
// prints first characture of $number or a 0
imagechar($im, 7, 0, 0, $number, $black);//edit 7 to change font size
header('Content-type: image/png');
imagepng($im);
?> that uses better filtering now
<?php
$var=$_GET["number"];
$int_options = array("options"=>array("min_range"=>0, "max_range"=>9));
$number=filter_var($var, FILTER_VALIDATE_INT, $int_options);
if (!$number || $number==""){$number="0";}
$back=$number-1;
$next=$number+1;
if ($number=="0"){$back="9";}
if ($number=="9"){$next="0";}
echo "<html><body><div align='center'>";
echo "<img src='number.php?number={$number}' border='0' /><br /><br />";
echo "<form method='GET'><input type='text' size='3' name='number'><br /><input type='submit' value='New Number'></form>";
echo "<br /><br />or...<br /><br />";
echo "<form method='GET'><input type='hidden' id='num' name='number' value=''><input type='submit' onclick='document.getElementById(\"num\").value=\"{$back}\"' value=' < '><input type='submit' onclick='document.getElementById(\"num\").value=\"{$next}\"' value=' > '></form>";
echo "</div></body></html>";
?>since i dont know what you want yet (i do simple stuff like this just because its fun for me to learn it and play with it) this is a sample for you to play with. using imagechar() only displays the first characture in a string but there are other functions to do for something else. it would look dumb if when you got to 10, 11, 12 etc for it to only display the 1 so i added some conditions to make the arrows loop in counting from 0-9
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.