The Problem: I keep receiving the error "Warning: imagecopymerge() expects parameter 2 to be resource"
Note: I have tried using both the global $_FILES and a saved image.
The Call:
Code: Select all
if($extension == 'jpg' || $extension == 'png' || $extension == 'jpeg' && $width >= 200){
$image = new WatermarkImage();
$image->load($_FILES['image']['tmp_name']);
$image->save($_FILES['image']['tmp_name']);
}
Code: Select all
class WatermarkImage {
var $image1;
var $image_type;
function load($filename) {
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if( $this->image_type == IMAGETYPE_JPEG ) {
$watermark = imagecreatefrompng("classes/watermark.png");
list($width, $height) = getimagesize($filename);
//set new image height (image height + watermark height)
$newHeight = $height + 40;
//create canvas
$this->image1 = imagecreate($width, $newHeight);
//choose RGB color
$white = imagecolorallocate($this->image1,233,234,235);
//fill canvas
imagefill($this->image1,0,0,$white);
//calculate watermark cords
$y = $newHeight-40;
$x = ($width - 200)/2;
//tosses primary image at the top of canvas
imagecopymerge($this->image1, $filename, 0, 0, 0, 0, $width, $height, 100);
//centers watermark below image
imagecopymerge($this->image1, $watermark, $x, $y, 0, 0, 200, 40, 100);
imagedestroy($watermark);
$this->image1 = imagecreatefromjpeg($filename);
} elseif( $this->image_type == IMAGETYPE_GIF ) {
$this->image1 = imagecreatefromgif($filename);
} elseif( $this->image_type == IMAGETYPE_PNG ) {
$this->image1 = imagecreatefrompng($filename);
}
}
function save($filename, $image_type=IMAGETYPE_JPEG, $permissions=null) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image1,$filename);
imagedestroy($this->image1);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image1,$filename);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image1,$filename);
}
if( $permissions != null) {
chmod($filename,$permissions);
}
}
}