You are here: Need Help with GD Creating a Watermarked Image « PHP Programming Language « IT news, forums, messages
Need Help with GD Creating a Watermarked Image

Posted by ameshkin on 10/01/06 22:35

Hi,
Im pretty new at PHP and need help with something very simple. I wrote
a function which watermarks an image. The function works, but i can't
figure out how to output the image into a file.

I want to feed this function a URL, $image..and at the end of this
code, I want to overwrite the $image file with the new watermarked
$image file. Im getting an error stating that this file cannot be
opened.

<?php

function watermark($image) {
//$image = $HTTP_GET_VARS['image']; // Useful if using in an img tag to
call images
//$image = str_replace(array("/", ".."), "", $image); // Prevent abuse
$overlay =
'/home/httpd/vhosts/picmonkey.com/httpdocs/ADMIN/overlay.png';
$dir = '/home/httpd/vhosts/picmonkey.com/httpdocs/IMAGEUPLOADS/';

// A default image for the demo...remove if you wish.


// Set offset from bottom-right corner
$w_offset = 0;
$h_offset = 0;

$extension = strtolower(substr($image, strrpos($image, ".") + 1));

// Load image from file
switch ($extension)
{
case 'jpg':
$background = imagecreatefromjpeg($image);
break;
case 'jpeg':
$background = imagecreatefromjpeg($image);
break;
case 'png':
$background = imagecreatefrompng($image);
break;
case 'gif':
$background = imagecreatefromgif($image);
break;
default:
die("Image is of unsupported type.");
}

// Find base image size
$swidth = imagesx($background);
$sheight = imagesy($background);

// Turn on alpha blending
imagealphablending($background, true);

// Create overlay image
$overlay = imagecreatefrompng($overlay);

// Get the size of overlay
$owidth = imagesx($overlay);
$oheight = imagesy($overlay);

// Overlay watermark
imagecopy($background, $overlay, $swidth - $owidth - $w_offset,
$sheight - $oheight - $h_offset, 0, 0, $owidth, $oheight);

// Output header and final image
//header("Content-type: image/jpeg");
//header("Content-Disposition: filename=" . $image);
//imagejpeg($background,'/home/httpd/vhosts/picmonkey.com/httpdocs/ADMIN/test.jpg');

// Destroy the images
imagedestroy($background);
imagedestroy($overlay);


}
?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация