PHP Image Creation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gerit99
Forum Newbie
Posts: 6
Joined: Mon Mar 04, 2013 10:19 am

PHP Image Creation

Post by gerit99 »

I made some PHP code, but it ain't working. It gives me a total black image with pants on top.

Code: Select all

<?php
session_start();
//You no getting da' database bro!
$id = $_GET['id'];
$main = "resources/charN.png";
$pants = "resources/AlienPants.png";
$shirt = "transparant.png";
$hair = "transparant.png";
$weapon = "transparant.png";
$face = "transparant.png";
$profileInfo = mysql_query("SELECT * FROM users WHERE userID=$id");
while ($row6=mysql_fetch_assoc($profileInfo)){

$displayItems = mysql_query("SELECT * FROM items WHERE itemID='".$row6['userShirt']."'");
while ($row22=mysql_fetch_assoc($displayItems)){
$shirt = "resources/".$row22['itemImg'];
}
$displayItems = mysql_query("SELECT * FROM items WHERE itemID='".$row6['hair']."'");
while ($row22=mysql_fetch_assoc($displayItems)){
$hair = "resources/".$row22['itemImg'];
}
$displayItems = mysql_query("SELECT * FROM items WHERE itemID='".$row6['userShoes']."'");
while ($row22=mysql_fetch_assoc($displayItems)){
$shoes = "resources/".$row22['itemImg'];
}
$displayItems = mysql_query("SELECT * FROM items WHERE itemID='".$row6['userPants']."'");
while ($row22=mysql_fetch_assoc($displayItems)){
$pants = "resources/".$row22['itemImg'];
}
$displayItems = mysql_query("SELECT * FROM items WHERE itemID='".$row6['userWeapon']."'");
while ($row22=mysql_fetch_assoc($displayItems)){
$weapon = "resources/".$row22['itemImg'];
}
$displayItems = mysql_query("SELECT * FROM items WHERE itemID='".$row6['userFace']."'");
while ($row22=mysql_fetch_assoc($displayItems)){
$face = "resources/".$row22['itemImg'];
}
}
/*echo $pants;
echo $shirt;
echo $weapon;
echo $face;
echo $shoes;
echo $main;*/
$main = imagecreatefrompng($main);
$pants = imagecreatefrompng($pants);
$shirt = imagecreatefrompng($shirt);
imagealphablending($main, true);
imagesavealpha($main, true);

imagecopymerge($main, $pants, 0, 0, 0, 0, 200, 200, 100); //have to play with these numbers for it to work for you, etc.

header('Content-Type: image/png');
imagepng($main);

imagedestroy($main);
imagedestroy($pants);
imagedestroy($shirt);

?>

User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: PHP Image Creation

Post by Jade »

Turn alpha blending off on the first image layer so that it will save it's transparency and turn it on for all of the others.
Post Reply