Log in

View Full Version : Whats wrong here [PHP GD]



Moh
22-07-2008, 06:01 PM
Well we have GD installed on our server, or else all the other GD images around the site wouldn't work (Then again, I think you have to set which image types can work)

Heres the contents of our file:
Yes, all the urls are correct :P


<?php

$name = $_GET["habbo"];
$hotel = $_GET["hotel"];

header("Content-Type: image/gif");

$im = imagecreatefrompng("spotlight.PNG");

$thumbWidth = "60";
$thumbHeight = "120";
$url = "http://www.habbo.$hotel/habbo-imaging/avatarimage?user=$name&action=&direction=4&head_direction=3&gesture=sml&size=l&img_format=png";
$srcImg = imagecreatefrompng($url);
$origWidth = imagesx($srcImg);
$origHeight = imagesy($srcImg);
$thumbImg = imagecreate($thumbWidth, $thumbHeight);
imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, imagesx($thumbImg), imagesy($thumbImg));
$ImgWhite = imagecolorallocate($thumbImg, 255, 255, 255);
imagefill($thumbImg, 0, 0, $ImgWhite);
imagecolortransparent($thumbImg, $ImgWhite);

$font = "Volter.ttf";
$size = "6.5";
$white = imagecolorallocate($im, 255, 255, 255);
$text = $name;
$img_w = imagesx($im);
$img_h = imagesy($im);

imagettftext($im, $size, 0, ($img_w / 2)-(strlen($name)*imagefontwidth($font) /2), 130, $white, $font, $name);


imagegif($im);
imagedestroy($im);

die();
?>


Moved by Invent (Forum Moderator) from Designing & Development: Please post in the correct forum next time, thanks :).

Decode
22-07-2008, 06:38 PM
What error are you getting?

EDIT: nvm I think I see the error, you have set the header to gif, but the image is png.

It either needs to be


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

$im = imagecreatefrompng("spotlight.png");
or


header("Content-Type: image/gif");

$im = imagecreatefromgif("spotlight.gif");

Independent
22-07-2008, 06:45 PM
Wow, thanks.

I just realized how to use GD.

Invent
22-07-2008, 06:46 PM
No Tom, he's outputting it as a gif, so it's fine :)

Decode
22-07-2008, 06:51 PM
No Tom, he's outputting it as a gif, so it's fine :)
Oh right lol, I didn't know GD could convert images :)

--ss--
22-07-2008, 06:57 PM
Create a PHP page and type the follwing code:

<?php echo phpinfo(); ?>
It should show you you're PHP info and what extra libraries you have installed like GD , scroll down to the GD section and see if you have the "Freetype" support enabled , you need the freetype library to use the getttftext function which you are using to write the text with ;).

Joe!
22-07-2008, 07:07 PM
Im unsure but i think that this part of the code needs to be $url = "http://www.habbo.".$hotel."/habbo-imaging/avatarimage?user=$name&action=&direction=4&head_direction=3&gesture=sml&size=l&img_format=png"; not 100% sure though, its because your using a variable i think.

--ss--
22-07-2008, 07:21 PM
Im unsure but i think that this part of the code needs to be $url = "http://www.habbo.".$hotel."/habbo-imaging/avatarimage?user=$name&action=&direction=4&head_direction=3&gesture=sml&size=l&img_format=png"; not 100% sure though, its because your using a variable i think.
Nope it does not seeing as I use the same method to get my Habbo images for my scripts and it works fine ;).

Independent
22-07-2008, 07:23 PM
Nope it does not seeing as I use the same method to get my Habbo images for my scripts and it works fine ;).
Eww..



$url = "http://www.habbo.". $hotel ."/habbo-imaging/avatarimage?user=". $name ."&action=&direction=4&head_direction=3&gesture=sml&size=l&img_format=png";

Why not just use the GET array thing, instead of creating another variable which contains the value of that.

Moh
22-07-2008, 07:33 PM
Create a PHP page and type the follwing code:

<?php echo phpinfo(); ?>It should show you you're PHP info and what extra libraries you have installed like GD , scroll down to the GD section and see if you have the "Freetype" support enabled , you need the freetype library to use the getttftext function which you are using to write the text with ;).
GD Support - enabled
GD Version - bundled (2.0.34 compatible)
FreeType Support - enabled
FreeType Linkage - with freetype
FreeType Version - 2.2.1
GIF Read Support - enabled
GIF Create Support - enabled
JPG Support - enabled
PNG Support - enabled
WBMP Support - enabled
XPM Support - enabled
XBM Support - enabled

Says its all enabled :S

Moh
23-07-2008, 10:33 PM
Erm, I still need help with this :P

kreechin
24-07-2008, 11:33 PM
I'll take a quick look at it now, see what i come up with.
I'm guessing this is one of them things habbo had a while back?

kreechin
24-07-2008, 11:58 PM
Couldn't edit my last post.
The problem lies with the font, I've just checked all the code, it all seems correct, the only isssue i see *as I've just tested the code* is the font, you need to make sure the font is present either in the folder with the file, or installed with the servers fonts, if it's not present it can't find the font, hense the error.

Moh
25-07-2008, 12:12 AM
Couldn't edit my last post.
The problem lies with the font, I've just checked all the code, it all seems correct, the only isssue i see *as I've just tested the code* is the font, you need to make sure the font is present either in the folder with the file, or installed with the servers fonts, if it's not present it can't find the font, hense the error.
It randomly started working :P

Thanks anyways.

Want to hide these adverts? Register an account for free!