PHP Pets

scipets2

New Member
Messages
28
Reaction score
1
Points
0
Hi, it's me again. I was wondering if there was a way to make my virtual pets practically any colour from a huge list. and for them to be able to choose accessories from a shop which all gets stored on the database.

anyway, all the script I need is a colour pallet. to send the colours to the database and code to display the pet in it's chosen colour with accessories in predefined places (eg. ear, head, footware etc.) Im sorry if this isn't too clear I will add more information if necessarily.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
What you want for an image picker view isn't entirely clear, but here's some stuff to get you started:
  1. There are plenty of color picker widgets for web pages
  2. Simply store the hex value in the table for the user's pet's stats
  3. To color the pet, you can use the GD extension, specifically the imagecolorset (to replace a single color in an indexed, non-shaded, cartoony image) or imagefilter (for true color or shaded images) functions. Use imagecopy to add one image to another, possibly after rotating it. You'll probably need to store the position and orientation of various body parts for each pet as an anchor point and rotation angle for the various accessories. The attachment point for each accessory will also probably need to be stored. When an accessory is drawn on a pet, rotate the accessory around the attachment point and match up the anchor point to the attachment point.
You could generate an image every time it's requested, or you could cache recent images to reduce server load.

Google will turn up plenty of information on using GD, including on using imagefilter function with the IMG_FILTER_COLORIZE filter.
 
Last edited:

scipets2

New Member
Messages
28
Reaction score
1
Points
0
Thanks, I was hoping I would have a code example however I could try. I've never used GD before
 
Last edited:

scipets2

New Member
Messages
28
Reaction score
1
Points
0
Ok, I've made the code, however it doesn't seem to be working
PHP:
<?php
$im = imagecreatefrompng("Dragon.png");

// Get the color index for the Dragon
$bg = imagecolorat($im, 64, 63);
$r = $_GET['r'];
$g = $_GET['g'];
$b = $_GET['b'];
// Set the fur colour to the database colour
imagecolorset($im, $bg, $r, $g, $b);

// Output the image to the browser
header('Content-type: image/png');

imagepng($im);
imagedestroy($im);
?>
That's what I've done so far however all I have is a black instead of transparent background, the pet colour doesn't change and If your thinking I've got the coordinates wrong. I haven't because no colours change. Any help?
 
Last edited:
Top