Currently I'm working on a dynamically created png for a signature on a Runescape board that I frequent. I've done some studying of the various commands and syntax I'll need to do so, but am having some trouble figuring out the best way to setup an array.
Basically, there are twenty one skills, plus some other data that needs to be filled in. All using digits 0-9 and the dash character (only used in the date).
I'm copying from an insert image (RSINSRT.PNG)

Note: The avatars, will have one randomly copied using Random(0-7)*70+1 for X coordinate, the Y, Width, and Height are the same.
to a template image (RSTMPLT.PNG)
I havn't gotten as far as loading the images yet, but am still working on the functions. Here is what I have so far.
PHP Code:
<?php
define("RAlign", 1);
define("LAlign", 2);
define("CAlign", 3);
function set_value ($srcimg, $dstimg, $dst_x, $dst_y, $value, $align)
{
$length = strlen($value); // Width in Characters
$width = $length * 8; // Width in Pixels
if ($length >= 5) // If It's more than or equal to 5 characters, it's the date
{
$width -= 4; // Two of the characters are only 6 pixels wide
}
switch ($align)
{
case LAlign: // If Left Aligned
break; // Use X Position, as is
case RAlign: // If Right Aligned
$dst_x -= $width; // Subtract width from X Position
break;
case CAlign: // If Center Aligned
$dst_x -= ($width / 2); // Subtract half of width from X Psition
break;
}
for ($i = 1; $i <= $length; $i++) // For each character in the string
{
if (substr($value, $i, 1) == "-") // If the character is a dash
{
$src_x = 101; // Use this X Position
$src_w = 6; // And this Width
} else
{ // Otherwise it's a number
$src_x = substr($value, $i, 1) * 10 + 1; // Figgure the X Position
$src_w = 8; // And use this Width
}
if (imgcopy($dstimg, $srcimg, $dst_x, $dst_y, $src_x, 114, $src_w, 12) != TRUE)
{
return false; // Some sort of problem occured
}
$dst_x += $src_w; // Increase X Position to Next Character
}
return true; // Mission Accomplished
}
function set_skills ()
{
$skill_list = array("farming", "attack", "strength", "defense", "range", "prayer",
"magic", "health", "agility", "herblore", "runecrafting", "slayer",
"theiving", "crafting", "fletching", "mining", "smithing", "fishing",
"cooking", "firemaking", "woodcutting");
}
?>
I am working on the function set_skills currently. As you can see, I need to feed to the set_value function the destination X and Y positions, along with the value. Currently the X and Y values will be as follows:
Code:
Skills { All Right Aligned --> X - Width }
| X = 59 | X = 125 | X = 191 | X = 257 | X = 439 | X = 505 | X = 571
----------|----------|---------|----------|--------------|-----------|----------|-------------
Y = 15 | Farming | | | | | | Reserved
----------|----------|---------|----------|--------------|-----------|----------|-------------
Y = 51 | Attack | Range | Health | Runecrafting | Theiving | Mining | Cooking
----------|----------|---------|----------|--------------|-----------|----------|-------------
Y = 87 | Strength | Prayer | Agility | Slayer | Crafting | Smithing | Firemaking
----------|----------|---------|----------|--------------|-----------|----------|-------------
Y = 123 | Defense | Magic | Herblore | | Fletching | Fishing | Woodcutting
Setting up an array such as array("Farming" => array("X" => 59, "Y" => 15, "Value" => 0)) etc, seems to me to be a very lengthy, and sloppy way of doing this, considering the redundancies that exist between X and Y positions between different skills.
Can anyone suggest a better way of doing this, so that I can easily step through using a foreach or for loop control, and feed the X, Y, and Value to the set_value function?
Also, How do I copy while using a transparent color so that the blue background doesn't also get copied?