Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2007
    Location
    Boca Raton, FL
    Posts
    119

    php imagecreatefrompng

    Hello, I'm not sure where this should go.. If it is in the wrong place mods please move.

    Okay, so I'm in the process of cloning a feature from a text based game. They have what you call userbars with info on them, but I can't figure out how they did it... I tried just using an iframe on the link to the userbar but its crappy. Then I tried using the iframe in the php imagecreatefrompng to create an image from it, but it doesnt read <font>'s <iframe>'s etc... only plain text. Now I know KNOW there using php imagecreatefrompng but I have NO clue how there processing the colors and custom stuff for names and stuff.

    Here's my code.

    Code:
    <?php
    require "global_func.php";
    include "config.php";
    global $_CONFIG;
    define("MONO_ON", 1);
    require "class/class_db_{$_CONFIG['driver']}.php";
    $db=new database;
    $db->configure($_CONFIG['hostname'],
     $_CONFIG['username'],
     $_CONFIG['password'],
     $_CONFIG['database'],
     $_CONFIG['persistent']);
    $db->connect();
    $c=$db->connection_id;
    if(isset($_GET['id']) AND ctype_digit($_GET['id'])) {
    $id = mysql_escape(trim($_GET['id']));
    }
    else {echo" Invalid Action";}
    if($id) {
    
    
        $query = sprintf("select level, username,money from users where userid = %u",$id);
        $result = mysql_query($query);
    
        $data = mysql_fetch_array($result);
    $info ="<iframe src='http://www.evilpirates.com/userbar.php?id=1'></iframe>";
    
    // Create a 400x18 image
    $im = imagecreatetruecolor(400, 18);
    $image = imagecreatefrompng("images/isonline.png"); // Get a background for jpg it is imagecreatefromjpg()
    imagealphablending($image, true); // setting alpha blending on         ~~~ remove if not using png
    imagesavealpha($image, true); // save alphablending setting (important)  ~~~ remove if not using png
    $black = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
    
    // Path to our ttf font file
    $font_file = 'arial.ttf'; // Any type of TTF font can take place as it is defining it to an image.
    
    
    imagefttext($image, 7, 0, 2, 10, $black, $font_file, $info);
    //            I     S  R  L  T      C         F        TX
    /*************************\
    I= Background image
    S= Font Size
    R= Right Border
    L= Left Border
    T= Top Border
    C Font Color* Colour
    F File to load eg.. arial.ttf
    TX Text Info
    */
    // Output image to the browser
    header('Content-Type: image/png');
    
    imagepng($image);
    imagedestroy($image);
    }
    else{echo"<br /> die";}
    ?>
    And here is the code to make the userbar.

    Code:
    <?
    require "global_func.php";
    //if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
    $userid=$_SESSION['userid'];
    //require "header.php";
    //include "who.php";
    include "config.php";
    global $_CONFIG;
    define("MONO_ON", 1);
    require "class/class_db_{$_CONFIG['driver']}.php";
    $db=new database;
    $db->configure($_CONFIG['hostname'],
     $_CONFIG['username'],
     $_CONFIG['password'],
     $_CONFIG['database'],
     $_CONFIG['persistent']);
    $db->connect();
    $c=$db->connection_id;
     $result=$db->query("SELECT u.*,c.* FROM users u LEFT JOIN cities c ON u.location=c.cityid WHERE u.userid={$_GET['id']}");
    $worked= $db->fetch_row($result);
    $hpperc=(int) ($worked['hp']/$worked['maxhp']*100);
    
    print "
    <style>
    #bar{
        font-size: 12px;
        font-family: 'Tahoma';
        padding: 4px;
    }
    </style>
    <table style='width: 100%;' height='10' id='bar'>
            <tr>
               <td bgcolor='black' style='border: 1px solid #1d4e80;'>".nameformat($worked['userid'])."</td>
               <td bgcolor='black' style='border: 1px solid #1d4e80;'><font color=white>Lvl: {$worked['level']}</font></td>
               <td bgcolor='black' style='border: 1px solid #1d4e80;'><font color=white>HP:</font> <font color=#00ff00>{$hpperc}%</font></td>
               <td bgcolor='black' style='border: 1px solid #1d4e80;'><font color=white>{$worked['cityname']}</font></td>
            </tr>
            </table>";
    
    ?>




  2. #2
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    Your first script is going to serve a .png image - nothing else. The iframe doesn't belong there, nor does any other kind of HTML markup. You should be calling it from within a web page (perhaps your second script) using an <img> tag or the CSS background-image style. ie.
    PHP Code:
    <img src="nameoffirstscript.php" /> 
    or
    PHP Code:
    <style type="text/css">
    #bar {
      
    background-imageurl(nameoffirstscript.php);
    }
    </
    style
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  3. #3
    Join Date
    Jul 2007
    Location
    Boca Raton, FL
    Posts
    119
    Well, the style when I did it just showed a white load... Then the first one with <img> it showed my background but doesnt show the data? I don't think <img> works on it.




  4. #4
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    For test purposes you can also point your browser directly to the first script and check the image it's producing. How you overlay the data is up to you - it looks like you're putting some kind of text into your image itself (imagefttext function) but you can also use CSS to overlay text on top of an image, either using positioning or background styling.

    For a simple upload bar you can even use a static image and alter the background-position style to display progress (with or without overlaid text).
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  5. #5
    Join Date
    Jul 2007
    Location
    Boca Raton, FL
    Posts
    119
    This is the script I want to show.....

    Code:
    <?
    require "global_func.php";
    //if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
    $userid=$_SESSION['userid'];
    //require "header.php";
    //include "who.php";
    include "config.php";
    global $_CONFIG;
    define("MONO_ON", 1);
    require "class/class_db_{$_CONFIG['driver']}.php";
    $db=new database;
    $db->configure($_CONFIG['hostname'],
     $_CONFIG['username'],
     $_CONFIG['password'],
     $_CONFIG['database'],
     $_CONFIG['persistent']);
    $db->connect();
    $c=$db->connection_id;
     $result=$db->query("SELECT u.*,c.* FROM users u LEFT JOIN cities c ON u.location=c.cityid WHERE u.userid={$_GET['id']}");
    $worked= $db->fetch_row($result);
    $hpperc=(int) ($worked['hp']/$worked['maxhp']*100);
    
    print "
    <style>
    #bar{
        font-size: 12px;
        font-family: 'Tahoma';
        padding: 4px;
    }
    </style>
    <table style='width: 100%;' height='10' id='bar'>
            <tr>
               <td style='border: 1px solid #1d4e80;'>".nameformat($worked['userid'])."</td>
               <td style='border: 1px solid #1d4e80;'><font color=white>Lvl: {$worked['level']}</font></td>
               <td style='border: 1px solid #1d4e80;'><font color=white>HP:</font> <font color=#00ff00>{$hpperc}%</font></td>
               <td style='border: 1px solid #1d4e80;'><font color=white>{$worked['cityname']}</font></td>
            </tr>
            </table>";
    
    ?>




  6. #6
    Join Date
    Jul 2007
    Location
    Boca Raton, FL
    Posts
    119
    I also found this but idk how I can get it to work in that script...

    <?
    (...session in progress...)
    $_SESSION['text']='some text...';
    $imgSrc='http://www.domain.com/file.php?id=1'.session_id();
    echo('<img src="'.$imgSrc.'"/>');
    unset($_SESSION['text']);
    ...
    ?>




  7. #7
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    If you're going to try and cobble together scripts you've found on the web without fully understanding what any of them are doing, you're in for a long hard ride.

    Here's a suggestion: Go back to first principles. Make a static image (Photoshop or whatever) and put it in a static HTML page as a mock-up of what you're trying to produce. In the process you should see exactly what needs to change to display progress (and / or whatever else you want to show). Once you're happy with the mockup, have your first PHP script produce the same image (for a given value of progress) and your second one produce the same HTML.
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  8. #8
    Join Date
    Jul 2007
    Location
    Boca Raton, FL
    Posts
    119
    i wish i could just do

    <img href='http://www.DOMAIN.com/userbar.php?id=1'>

    but its not working




  9. #9
    Join Date
    Jul 2007
    Location
    Boca Raton, FL
    Posts
    119
    I still haven't got this to work. =/ Anyone??




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •