Jump to content
MakeWebGames

Question - Is it possible to put an image as a username?


Gucci Mane

Recommended Posts

You can also use the GD Lib to create a img for the username

example

 

<?
// MakeWebGames.com :: Example of using the GD Library to change txt to img
header("Content-type: image/gif");
if(!$_GET['len']) $_GET['len']=100;
if(!$_GET['height']) $_GET['height']=40;
if(!$_GET['size']) $_GET['size']=20;
if(!$_GET['hline']) $_GET['hline']=$_GET['height']/2;
$image=imagecreate($_GET['len'],$_GET['height']);
$bg_colour = imagecolorallocate($image, 230, 230, 230);
$txt_colour = imagecolorallocate($image, 0x5F, 0x27, 0x25);
$trans=imagecolortransparent ($image ,$bg_colour);
imageantialias ($image,off);
imagettftext($image,$_GET['size'],0,0,$_GET['hline'],$txt_colour,'dearJoe_4_trial.otf',$_GET['string']);

imagegif($image);
imagedestroy($image);
?>

 

as attachment the OTF and a example GIF created with the above

Link to comment
Share on other sites

I wouldn't use it in the game script itself as it uses CPU power as memory from the server

What I would do is having at the signup create the username as gif and fwrite it to a file eg to /user/{username}.gif

ingame you simply call the username as a img src then

example of creating a img without proxying it to a browser

 

<?php
// Create a test source image for this example
$im = imagecreatetruecolor(300, 50);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);

// start buffering
ob_start();
// output jpeg (or any other chosen) format & quality
imagejpeg($im, NULL, 85);
// capture output to string
$contents = ob_get_contents();
// end capture
ob_end_clean();

// be tidy; free up memory
imagedestroy($im);

// lastly (for the example) we are writing the string to a file
$fh = fopen("./temp/img.jpg", "a+" );
   fwrite( $fh, $contents );
fclose( $fh );
?> 
Link to comment
Share on other sites

what I did was make the image.

Upload to cpanel

then edit user

and for there username I put

<img scr=filename.png>

where it says file name, change that to w/e the image you uploaded to your cpanels name

ex. you make a image upload to cpanel as testimg.png you would put <img scr=testimg.png> in the users username

Link to comment
Share on other sites

that woks also , but what if 1000 players want's to have a img as username ....

I was looking into a method for you how to auto generate a gif/jpg for the members and have it displayed as gif instead of a txt username (without going to edit the username field)

Link to comment
Share on other sites

@ThaSkiMaskWay: Yes your way of doing this works fine, however imagine yourself making about a few thousands, if not a million, username images just because a user changes his name? It can all work fine, however this isn't automated, you have to spend time doing it (even though, adding a new layer with a username doesn't take long, you still have to upload it, and edit a users settings).

What mdshare did here, is post the base of a script that would automate this process. This means that you wouldn't need to spend creating a new image each time a user changes his or her nickname - which can be a real pain if you have quite a userbase! Therefore automating this event, would give you more time to spend on other things, while users get there images quite instantly, with the possibility of adding extra options to the script. They're happy, you are probably happy too. And once it's made, you actually don't have to look at it anymore - unless you want to change the base image - which takes up a little bit of time and you're good again.

But keep in mind that having such a script comes with a price! It isn't a php version of photoshop, and it's quite heavy on resources, yet this can have quite a lot of possibilities.

I hope this can clear up some extra things.

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...