...

View Full Version : GD: Watermark not working.



Majoracle
11-16-2007, 07:54 AM
It creates and converts images to jpg like it should but the watermark doesn't work. And the path to the watermark is correct; I checked it like 3 times. Anyway, here's the PHP:


function makeimage($image, $watermark)
{
$img_explode = explode('.', $image);
$img_ext = $img_explode[1];

// create new image
switch ($img_ext)
{
case 'gif':
$new_image = @imagecreatefromgif($image);
break;

case 'jpg':
$new_image = @imagecreatefromjpeg($image);
break;

case 'jpeg':
$new_image = @imagecreatefromjpeg($image);
break;

case 'png':
$new_image = @imagecreatefrompng($image);
break;
}

$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);

$size = getimagesize($image);

$dest_x = $size[0] - $watermark_width - 5;
$dest_y = $size[1] - $watermark_height - 5;

// merge watermark and image
imagecopymerge($new_image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);

imagedestroy($watermark);

return $new_image;
}

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

$dir = $_SERVER['DOCUMENT_ROOT'];
$imagedir = $dir."/img/gallery/";
$watermark = $dir."/img/watermark.png";

$imagename = $_FILES['image']['name'];
$imagepath = $imagedir.$imagename;

move_uploaded_file($_FILES['image']['tmp_name'], $imagepath) or die("Unable to upload.");

$imagenewname = "img".rand(1,999999).".jpg";
$imagenewpath = $imagedir.$imagenewname;

rename($imagepath, $imagenewpath);
unlink($imagepath);

// make image
$image = makeimage($imagenewpath, $watermark);
imagejpeg($image);

Thanks in advance.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum