Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 07-13-2005, 09:20 PM   #1 (permalink)
Rafkin
Registered User
 
Rafkin's Avatar
 
Join Date: Mar 2004
Posts: 20
Rafkin is on a distinguished road
Dynamic Images

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$i1) == "-")                // 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$i1) * 10 1;    // Figgure the X Position
            
$src_w 8;                                    // And use this Width
        
}
        
        if (
imgcopy($dstimg$srcimg$dst_x$dst_y$src_x114$src_w12) != 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?
Rafkin is offline   Reply With Quote
Old 07-13-2005, 10:36 PM   #2 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
Maybe I'm missing something, but why not just seperate the pictures and load a single image per skill/class whatnot?
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Old 07-14-2005, 12:32 AM   #3 (permalink)
Rafkin
Registered User
 
Rafkin's Avatar
 
Join Date: Mar 2004
Posts: 20
Rafkin is on a distinguished road
I'm not sure I follow. getting the pieces of the source copied to the background isn't difficult to do. I don't like to litter my image folder with a bunch of different pictures if I can help it anyway. What I need to do, however, is generate 2, 3, and 4 digit numbers that change periodically.

Currently I just copy the numbers into place manually, editing the picture every time. But what I need to do is make it so that I can fetch the values from either mysql or from an ascii file, and copy the images of the numbers to their destination. The date, would be date last updated, or last time I edited the values.

So what I'm lookng for is the best way to setup the array, so that I can step through each skill, and feed the destination X and Y coordinate, along with the value that i'll fetch from some sort of data source.

Also, I need to figgure out how to copy the numbers transparently so that the blue background doesn't get copied alnong with the images. Same would apply for the avatar which will be randomly chosen and inserted.
Rafkin is offline   Reply With Quote
Old 07-14-2005, 01:15 AM   #4 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
Well I don't know if it's the best way of setting up your array but you mentioned you want to avoid redundant data so you could note that every x coordinate is equal to 59 + (66 * Xindex) and every y coordinate is equal to 15 + (36 * Yindex). Value is undefined so far but I assume it's going to show up eventually.

You could make your array look like array( "Farming" => array(0,0,0), ... ) Then run each value through the conversion function as you loop through e.g, $x = 59 + 66 * $skill_array["Farming"][0]; $y= 15 + 36 * $skill_array["Farming"][1];

Alternatively, you could make your data more compact by doing array( "Farming" => "0.0.0", ... ) In ths case you run it through explode or split before you convert it to the true values for set_value().

In each case it's just trading data compactness for processing time.
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Old 07-14-2005, 01:31 PM   #5 (permalink)
Rafkin
Registered User
 
Rafkin's Avatar
 
Join Date: Mar 2004
Posts: 20
Rafkin is on a distinguished road
ok.. using the mathematical method would be perfered, however, the X one only works for the first four colums, then a gap throws the rest off.

However, I like the idea of saving the coords as "X,Y" and exploding them as needed. It's cleaner than what I originally was going to do, so I may go that route. As for values, since I'll be reading those from an outside source, I figure I should just put those into a seperate array.

Thanks for the help.
Rafkin is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic CSS files with PHP metazai PHP 28 06-28-2005 10:30 AM
Using PHP to retrieve images stored in MySQL metazai PHP 11 04-06-2005 01:05 AM
Resizing images on the fly using GD? morpheuz PHP 8 03-08-2005 05:44 AM
New images reaffirm planet is lord of rings redhead Code Newbie News 0 07-05-2004 12:56 AM
dynamic allocation..urgent help needed!!! kashif Standard C, C++ 4 04-21-2003 08:50 AM


All times are GMT -8. The time now is 07:02 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting