Jump to content

Multiple Color-Blended Stacked Images in GD


takua108

Recommended Posts

Okay, I need some help getting some PHP/GD code that'll allow me to draw a graphic of the user's player for an indie game that I'm doing the website for. Only problem is that (in the game) the user's player graphic consists of (from bottom-to-top in drawing order) legs, torso, and armor. Each section's color can be customized with any RGB color.

Anyways, now I need to draw the graphic for the user's player on his or her stats page on the website, using MySQL values for the color. The color is stored as RRRGGGBBB, and I've already figured out how to retrieve it and use substr() to get each color component. I've even already partially figured out the image blending code:
PHP Code:
[code]<?php

// Load the sprite into memory
$imgTorso=imageCreateFromPng("images/sprite.png");
$imgBlend=imageCreateFromPng("images/sprite.png"); // Load his clone too

// Load the height and width of the image
$sx=imagesx($imgBlend);
$sy=imagesy($imgBlend);

// Define the color to blend the image with
$color=imagecolorallocate($imgBlend,$_GET['r'],$_GET['g'],$_GET['b']);
$background=imagecolorallocate($imgBlend,255,255,255);

// Blend the image
imagefilledrectangle($imgBlend,0,0,$sx,$sy,$color);

// Output for Browser
imagecopymerge($imgTorso,$imgBlend,0,0,0,0,$sx,$sy,50);
imagefill($imgTorso,0,0,$background);
imagecolortransparent($imgTorso,$background);

header("Content-type: image/png");
imagePng($imgTorso);
?>[/code]

Can anyone help me get code that both blends each part of the graphic as well as draws them on top of each other? I have half of the solution above; I just need the rest.

Thanks in advance,
~takua108
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.