Malmoc
Malmoc

Reputation: 109

PHP GD: Image cannot be displayed because of errors

Okay.. so I've been trying to make a 'signature' for a game that I play. The only catch is, I've been running into quite a few problems when wanting to insert an Avatar & Online/Offline image.

The two things I've been trying to do is:

  1. Get user status from a webpage habplus.com/home/[username] by checking if habbo_offline.gif is present.

    if(strpos(file_get_contents('http://www.habpl.us/home/'.$username.''), 
              'habbo_offline.gif') == true) {
    
  2. Grab users image and display on the final image

    function habSigFigure($username){
            $omgfig = 'http://www.habpl.us/figure.php?user='.$username.'&img_format=gif';
            return $omgfig; 
    
    //place habbo avatar
        $habsigfig = imagecreatefromgif($omgfig);
        imagecopy($img, $habsigfig, 13, 32, 0, 0, imagesx($habsigfig), imagesy($habsigfig));*/
        //place habbo avatar
    

I've included the entire source code, and the and the page can be accessed here -Another link with variables included

Hope you can help.. Sincerely yours, Malmoc

<?php
include 'config.php';
$username=$_REQUEST["user"];
$grabstat3 = fopen("http://habplus.com/fansitetools/userStats.php?user={$username}&stat=motto", "r"); 
while (!feof($grabstat3)){ $motto1 = fgets($grabstat3);
}   
fclose($grabstat3);
$username=$_REQUEST["user"];
$grabstat2 = fopen("http://habplus.com/fansitetools/userStats.php?user={$username}&stat=pixels", "r"); 
while (!feof($grabstat2)){ $pixels1 = fgets($grabstat2);
}
fclose($grabstat2);
$username=$_REQUEST["user"];
$grabstat1 = fopen("http://habplus.com/fansitetools/userStats.php?user={$username}&stat=credits", "r"); 
while (!feof($grabstat1)){ $credits1 = fgets($grabstat1);
}
fclose($grabstat1);



$pixels = 'Pixels: '.$pixels1.'';
$credits = 'Credits: '.$credits1.'';
$motto = 'Motto: '.$motto1.'';
/* Get custom img */
if(empty($_REQUEST['img'])){
    $img = 'default.png';
}else{ 
    $img =$_REQUEST['img'];
}

/* TEXT COLORS */
$red =$_REQUEST['red'];
$green =$_REQUEST['green'];
$blue =$_REQUEST['blue'];

/* Font size */
$fsize =$_REQUEST['fsize'];


    /*function habSigStatus($username){
        if(strpos(file_get_contents('http://www.habpl.us/home/'.$username.''), 'habbo_offline.gif') == true){
            return false;
        }else{
            return true;


    function habSigFigure($username){
        $omgfig = 'http://www.habpl.us/figure.php?user='.$username.'&img_format=gif';
        return $omgfig;
    }
    }
}*/


/*

    //place habbo avatar
    $habsigfig = imagecreatefromgif($omgfig);
    imagecopy($img, $habsigfig, 13, 32, 0, 0, imagesx($habsigfig), imagesy($habsigfig));*/
    //place habbo avatar



    //habbo status
    if(strpos(file_get_contents('http://www.habpl.us/home/'.$username.''), 'habbo_offline.gif') == true){
        $status_img = imagecreatefromgif('habbo_offline.gif');
    }else{
        $status_img = imagecreatefromgif('habbo_online.gif');
    }
    imagecopy($image, $status_img, 403, 96, 0, 0, 50, 16);
    //habbo status


$image = imagecreatefrompng($img); 
$font_color = imagecolorallocate($image, $red, $green, $blue); 
imagefttext($image, $fsize, 0, 3, 12, $font_color, './volt.ttf', $credits);  /* top left     */
imagefttext($image, $fsize, 0, 403, 12, $font_color, './volt.ttf', $pixels); /* top right    */
imagefttext($image, $fsize, 0, 3, 96, $font_color, './volt.ttf', $motto);    /* bottom left  */
imagefttext($image, $fsize, 0, 403, 96, $font_color, './volt.ttf', $online); /* bottom right */
/* imagefttext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text [, array $extrainfo]) */
header('Content-type: image/png'); 
imagepng($image); 
imagedestroy($image); 


?>

Upvotes: 0

Views: 673

Answers (2)

Eduardo Ortiz
Eduardo Ortiz

Reputation: 407

$image should be a valid resource, in your code $image is null

  $image = imagecreatefrompng($img); 
  imagecopy($image, $status_img, 403, 96, 0, 0, 50, 16);

you can use

   $image = imagecreatetruecolor(50, 16); //width,height
   imagecopy($image, $status_img, 403, 96, 0, 0, 50, 16);

Upvotes: 1

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324600

Here's your problem, fairly derpy to be honest:

imagecopy($image, $status_img, 403, 96, 0, 0, 50, 16);
$image = imagecreatefrompng($img); 

You kind of need to create the image before you can copy to it. Swap those two lines around and you should be good.

Upvotes: 1

Related Questions