Jump to content

[SOLVED] Image generation: Adding a static image within my dynamic image


slapdashgrim

Recommended Posts

is  there a way to add a static image like

1.png

into my dynamic image that pulls a users info from a database?

like this

sig.php?id=2

to the left of rank i want to put the image that signifys a rank.

 

any help would be aprecheated.

src code for my image

<?php

Header('Content-type: image/png');
Header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
Header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
Header('Pragma: no-cache');

//mysql
if ($dbc = @mysql_connect ('grimhqco.dot5hostingmysql.com','grimhq','pass')) {



                        mysql_select_db('grimhqco_roster');

                        //query
                        $query = "SELECT player_name, player_id, player_rank, player_activity FROM roster_players";

                            if ($r = mysql_query ($query)) {
                            while ($row = mysql_fetch_array ($r)) {
                                  if ($row['player_id'] == $_GET['id']){
                            $name = $row['player_name'];
                            $rank1 = $row['player_rank'];
                            $activity = $row['player_activity'];
                                  }
                            }
                            }

                         mysql_close();
                         }

//  get rank
if ($rank1 == 1) {
$rank ="Generaal";
}
if ($rank1 == 2) {
$rank ="Luitenant-Generaal";
}
if ($rank1 == 3) {
$rank ="Generaal-Majoor";
}
if ($rank1 == 4) {
$rank ="Brigade-Generaal";
}
if ($rank1 == 5) {
$rank ="Kolonel";
}
if ($rank1 == 6) {
$rank ="Luitenant-Kolonel";
}
if ($rank1 == 7) {
$rank ="Majoor";
}
if ($rank1 ==  {
$rank ="Eerste-Luitenant";
}
if ($rank1 == 9) {
$rank ="Tweede-Luitenant";
}
if ($rank1 == 10) {
$rank ="Waandrig";
}
if ($rank1 == 11) {
$rank ="Kapelmeester";
}
if ($rank1 == 12) {
$rank ="Sergeant-Majoor";
}
if ($rank1 == 13) {
$rank ="Sergeant der 1e klasse";
}
if ($rank1 == 14) {
$rank ="Sergeant";
}
if ($rank1 == 15) {
$rank ="Korporaal der 1e klasse";
}
if ($rank1 == 16) {
$rank ="Korporaal";
}
if ($rank1 == 17) {
$rank ="Soldaat der 1e klasse";
}
if ($rank1 == 18) {
$rank ="Soldaat";
}
//end get rank

//get active
if ($activity == 1){
$active = "In-active";
}
if ($activity == 2){
$active = "Game activity";
}
if ($activity == 3){
$active = "Forum activity";
}
if ($activity == 4){
$active = "Full activity";
}
if ($activity == 5){
$active = "LOA";
}
//end get active
$sig_info = "Rank = $rank,  Activity = $active";

// define sig dimentions
$img_width = 555;
$img_height = 250;

// define background image (must match dimentions and must be png)
$bgimage = imagecreatefrompng("bg.png");
$rankimg = imagecreatefrompng("ranks/$rank1.png");

// define text color
$textcolor = imagecolorallocate ($bgimage, 255, 255, 255); // image, red, green, blue -- $bgimage, 255, 255, 255 would create white

// output sig
imagefilledrectangle($rankimg, 75, 100, 149, 160, $textcolor);
imagestring($bgimage, 5, 86, 50, $name, $textcolor);
imagestring($bgimage, 3, 149, 100, $sig_info, $textcolor);// image, text size, x pos, y pos, color

imagepng($bgimage);
imagedestroy($bgimage);

?>

 

by the way i know the checking of the rank is not the way i should do it but i wrote this script along time ago.

i will fix it if can find a way to put rank images within my image.

 

Thankyou.

Link to comment
Share on other sites

lol, umm, you could try absolute positioning possibly but that would require changing a few things about your display. If you use the bgimage as a table background than put the rank pic in the table normally and then use a div or something to put it where you want you could get some decent results.

Link to comment
Share on other sites

lol, umm, you could try absolute positioning possibly but that would require changing a few things about your display. If you use the bgimage as a table background than put the rank pic in the table normally and then use a div or something to put it where you want you could get some decent results.

well im not doing this in html its in PHP.

i cant have divs in a image.

thankyou tho.

 

and i will look up that GD function ty

Link to comment
Share on other sites

Well you beat me to it. I have some code to show you. I'm not sure if you wanted the second image to be so light but here's my version. The image has 100% opacity. One thing too, is since you're using PNG files you might want to change the white background of the second image to an alpha then use the imagealphablending function:

 

Preview -> http://astuckpixel.com/subs/dev/merge/merge.php

 

<?php

header("Content-type: image/png");

// Main Image (550x250)
$dest = imagecreatefrompng("sig.png");

// OverLay Image (60x74)
$src = imagecreatefrompng("1.png");
//imagealphablending($src, true);

// Copy and merge
imagecopymerge($dest, $src, 75, 100, 0, 0, 60, 75, 100);

// Output and free free from memory
imagepng($dest);

imagedestroy($dest);
imagedestroy($src);

?>

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.