0
<?
$connection = mysql_pconnect("***","***","***");
mysql_select_db("***");
$id = mysql_real_escape_string(strip_tags(stripslashes($_GET['id'])));
$getUser = mysql_query("SELECT * FROM user WHERE id='".$id."'");
$gU = mysql_fetch_object($getUser);

$Background = $gU->Background;
if (empty($Background)) {
$Background = "";
}
$Hat = $gU->Hat;
if (empty($Hat)) {
$Hat = "";
}

class StackImage
{
  private $image;
  private $width;
  private $height;

  public function __construct($Path)
  {
    if(!isset($Path) || !file_exists($Path))
      return;
    $this->image = imagecreatefrompng($Path);
    imagesavealpha($this->image, true);
    imagealphablending($this->image, true);
    $this->width = imagesx($this->image);
    $this->height = imagesy($this->image);
  }

  public function AddLayer($Path)
  {
    if(!isset($Path) || !file_exists($Path))
      return;
    $new = imagecreatefrompng($Path);
    imagesavealpha($new, true);
    imagealphablending($new, true);
    imagecopy($this->image, $new, 0, 0, 0, 0, imagesx($new), imagesy($new));
  }

  public function Output($type = "image/png")
  {
    header("Content-Type: {$type}");
    imagepng($this->image);
    imagedestroy($this->image);
  }

  public function GetWidth()
  {
    return $this->width;
  }

  public function GetHeight()
  {
    return $this->height;
  }
}
$Image = new StackImage("".$Background."");
$Image->AddLayer("".$Hat."");

$Image->Output();

?>

I get these errors...

PHP Warning: imagepng() expects parameter 1 to be resource, null given in G:\PleskVhosts\social-idiots.com\httpdocs\avi.php on line 57
PHP Warning: imagedestroy() expects parameter 1 to be resource, null given in G:\PleskVhosts\social-idiots.com\httpdocs\avi.php on line 58

This is an old code I have been using for a while, so I have never really worked with images in php...

2
Contributors
1
Reply
14
Views
3 Years
Discussion Span
Last Post by diafol
1
class StackImage
{
  private $image;
  private $width;
  private $height;
  public function __construct($Path)
  {
    if(!isset($Path) || !file_exists($Path))
      return;
    $this->image = imagecreatefrompng($Path);
    imagesavealpha($this->image, true);
    imagealphablending($this->image, true);
    $this->width = imagesx($this->image);
    $this->height = imagesy($this->image);
  }
  public function AddLayer($Path)
  {
    if(!isset($Path) || !file_exists($Path))
      return;
    $new = imagecreatefrompng($Path);
    imagesavealpha($new, true);
    imagealphablending($new, true);
    imagecopy($this->image, $new, 0, 0, 0, 0, imagesx($new), imagesy($new));
  }
  public function Output($type = "image/png")
  {
    header("Content-Type: {$type}");
    imagepng($this->image);
    imagedestroy($this->image);
  }
  public function GetWidth()
  {
    return $this->width;
  }
  public function GetHeight()
  {
    return $this->height;
  }
}
$Image = new StackImage("Cl.png");
$Image->AddLayer("K.png");
$Image->Output();

When I used hard-coded, existing images, it worked fine.

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.