i hate gd

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

i hate gd

Post 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.
yum-jelly
Forum Commoner
Posts: 98
Joined: Sat Oct 29, 2005 9:16 pm

Post 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
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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());
?>
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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.
Post Reply