Dynamic Images

Discussion in 'Off Topic' started by Evan, Mar 21, 2007.

  1. Evan

    Evan League Commissioner

    Messages:
    1,807
    Likes Received:
    0
    Trophy Points:
    0
    Any of you guys know how to write dynamic text onto an image file using php? Like those spam ads that display your IP?

    It would make updating all the CW signature files much easier if they just read their info (rank/name/squad/etc) from a database.
     
  2. dizzyone

    dizzyone I've been drinking, heavily

    Messages:
    5,771
    Likes Received:
    0
    Trophy Points:
    0
    Google is your friend.
     
  3. Evan

    Evan League Commissioner

    Messages:
    1,807
    Likes Received:
    0
    Trophy Points:
    0
    I've tried various methods in the past using png images that work when you browse directly to the image, but don't work when linking to the image from a forum. I've also tried flash.

    Is there a way w/ gif images?
     
  4. ^Dee^

    ^Dee^ Former Super Moderator

    Messages:
    4,385
    Likes Received:
    6
    Trophy Points:
    0
    I'm guessing you're going to need a .php script.

    Though I'm sure it wouldn't be too hard, simply to use a layered image and changing the text when need be :)
     
  5. Evan

    Evan League Commissioner

    Messages:
    1,807
    Likes Received:
    0
    Trophy Points:
    0
    It is tedious to have to edit the image in photoshop and upload it to the server after every rank promotion, but I will continue to do it unless anyone can find a php script suitable. I haven't been able to find a php/gif script.
     
  6. KILLX

    KILLX Banned

    Messages:
    4,357
    Likes Received:
    0
    Trophy Points:
    0
    you could just try making all the promotion sigs for the person in one go when the join, that may be easier.
     
  7. dizzyone

    dizzyone I've been drinking, heavily

    Messages:
    5,771
    Likes Received:
    0
    Trophy Points:
    0
    or you could make actions in photoshop
     
  8. rampantandroid

    rampantandroid Member

    Messages:
    2,664
    Likes Received:
    0
    Trophy Points:
    0
    I imagine that you can do this in languages like Ruby on Rails and ASP, but its very easy to do in PHP - if you're on a recent build of PHP (4.x and up I think) you have PHP GD compiled into the PHP DLLs and such.

    GD allows you to create a background, and overlay images on this background at certain Cartesian coordinates, as well as text. When I first saw your CW signatures on this forum, I was all crazy because I thought you used a PHP script...

    An example can be found here: http://the42nd.com/modules.php?name=Roster

    I programmed that whole system - each uniform image is generated dynamically, as you view it, pulling the information required from a MySQL database...it isn't that fast (I need to look at how to optimize it later) but it does the job. Behind that roster system there is a backend that allows you to change what displays on each person's uniform - their name, awards and so on.

    www.php.net will be your friend...

    Code:
    if(!$Retired)
    	$background = imagecreatefrompng("./uniform/uni_active.png");
    else
    	$background = imagecreatefrompng("./uniform/uni_retired.png");
    Here's how you add text (if you want to know how the function works, search it on php.net)
    Code:
    $textsz = imagettfbbox(10, 0, $font, $LName); //Create text
    $textsize = $textsz['2'] - $textsz['0']; //change size of textbox, so it fits in the little black area of the uniform, without going out
    $textsize = $textsize / 2;
    $x_place = 228 - $textsize; //Where it will be placed - centered in the black area
    ImageTTFText ($background, 10, 0, $x_place, 168, $txt_color, $font, $LName);
    And if you want to place an image on this as well:

    Code:
    if($Some_Condition== '1')
    	{
    		$addimage = imagecreatefrompng("./images/cw.png"); //open image and put in memory
    		imagecopy($background, $addimage, '44','396','0','0',imagesx($addimage), imagesy($addimage));  //Adds the image to the background at a certain X,Y
    		imageDestroy($addimage);  //Delete from memory...be nice to your servers memory, and delete images once done.
    	}
    When done adding stuff, display it
    Code:
    //Print the image out
    header("Content-type: image/png");
    imagepng($background);
    imageDestroy ($background);

    To then view the image, do something like put it in img tags, or access it like so: http://www.the42nd.com/uniforms/image.php?id=143

    If you want, PM me or IM me or something, and I can give more specific help.
     
  9. Evan

    Evan League Commissioner

    Messages:
    1,807
    Likes Received:
    0
    Trophy Points:
    0
    Thanks a lot rampant. I'll give it a try this weekend.

    Do I have to do the "rename the folder to image.png" trick to get it to be displayable on forums?

    As for my photoshop file, I do have it setup so it as easy as it possibly could be... I just don't like having to upload new files. I'd rather login to an admin page and update the mysql.

    If I can't get things working rampant, think you might be interested in designing the script? I can send you the psd file so you can see what you'd be up against.

    dynamic crap:
    1. background file
    2. rank name
    3. rank image
    4. squad
    5. player name
     
  10. Niarbeht

    Niarbeht Member

    Messages:
    2,010
    Likes Received:
    0
    Trophy Points:
    0
    You can do it, evan! Heck, I could probably do it...

    And no, I won't do it.
     
  11. rampantandroid

    rampantandroid Member

    Messages:
    2,664
    Likes Received:
    0
    Trophy Points:
    0
    I wouldn't be totally adverse to doing it. A few things here though:

    How do you want to display the image? You're going to need to have some sort of admin/backend setup to add new members, set their rank, name and squad. From that, a switch statement can be made to properly overlay the images.

    What's needed to accomplish this is basic HTML (and javascript if you like form validation, ie, someone can't submit a member without a name), some PHP, and MySQL (or some database.) I'll assume you can easily get a new database, as you have a forum on your site that probably uses MySQL?

    to display on a forum:

    Well....this forum system doesn't like my display method...you;d have to save the output of the PHP script as a PNG or something.
     
    Last edited: Mar 22, 2007
  12. Evan

    Evan League Commissioner

    Messages:
    1,807
    Likes Received:
    0
    Trophy Points:
    0
    What I'd really like to do would be to use your method but with gif images. I hear that if you rename folder the function index.php file is in to an image name (like signature.gif) it can trick browsers into rendering it. There is some crap you need to put in the .htaccess file to make it not load the index.

    Anyway, yeah I have php 5 and mysql. So a .htpasswd-protected form page linking to a mysql database seems doable.
     
  13. rampantandroid

    rampantandroid Member

    Messages:
    2,664
    Likes Received:
    0
    Trophy Points:
    0
    I try to stray away from using a plain htpass, rather I integrated the whole system into the PHPNuke install we are using (and prior to PHPNuke it was Dragonfly CMS) - again, its allowing more control, and is more dynamic, but is more intricate as well.

    The last piece of code I posted - where I set the header - is how you SHOULD be able to get the browser to render it. I think the reason this board is not rendering it, is because the board only allows certain image types - jpeg, and gif are among them...not sure if PNG is.

    [​IMG]

    Nope, I guess PNGs work. The forum just won't display anything as an image that is doesn't know is an image. Bah.
     

Share This Page