Page 1 of 1

i hate gd

Posted: Sun Nov 20, 2005 1:06 pm
by shiznatix
im not good at gd at all but what i need to do is watermark a image. i upload the image and then i use this function

Code: Select all

<?php  

function watermark($img)
{
    $watermark = imagecreatefrompng('./images/watermark.png');  
    $watermark_width = imagesx($watermark);  
    $watermark_height = imagesy($watermark);  
    $image = imagecreatetruecolor($watermark_width, $watermark_height);  
    $image = imagecreatefromjpeg($img);  
    $size = getimagesize($img);  
    $dest_x = $size[0] - $watermark_width - 5;  
    $dest_y = $size[1] - $watermark_height - 5;  
    imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);  
    imagejpeg($image);  
    imagedestroy($image);  
    imagedestroy($watermark);  
}
?>
but that will just display the image if i throw the right header. i dont want it to display the image, i want it to save the image over the old, unwatermarked image. help please.

Posted: Sun Nov 20, 2005 1:11 pm
by yum-jelly
Just add the path to imagejpeg(); and the quality! If you don't add quality it default to 72


Code: Select all

imagejpeg ( $image, $img, 80 );

yj

Posted: Sun Nov 20, 2005 1:30 pm
by shiznatix
wow that was simple. i guess i should have RTFM. ok thanks

edit:

can i do the same thing with imagegif and imagepng? the manual did not really say anything

Posted: Sun Nov 20, 2005 2:05 pm
by josh
Quick 'hack' for functions that write to stdout instead of file

Code: Select all

<?
ob_start();
// function that outputs
file_put_contents('file', ob_get_clean());
?>

Posted: Sun Nov 20, 2005 3:30 pm
by onion2k
shiznatix wrote:can i do the same thing with imagegif and imagepng? the manual did not really say anything
Yes you can, but you'll need to miss out the quality argument coz gif and png don't have that.