Help - Search - Members - Calendar
Full Version: Watermark
Pixel2Life Forum > Member Tutorials and Requests > Forum Tutorial Archives > PHP Tutorials
Xuxiix
First of, this is my first tutorial. So please, please, tell me what I can improve. Also, I don't really speak english. Although I'll do my best.

Edit: Forgot to tell, this require GD. Read more at http://php.net/gd

CODE
<?php

/* (X) Tell the browser that this script, is a image. */
header("Content-type: image/png");

/* (U) Generate our watermark picture. */
$Watermark = imagecreatefrompng("watermark.png");
/* (X) Genererate our picture, where we want to put the watermark. */
$Image = imagecreatefromjpeg("image.jpg");

/* (I) Get the color at x: 0. y: 0. in our Watermark, and use that color, as the transparency color. */
imagecolortransparent($Watermark,imagecolorat($Watermark,0,0));

/*
* (I) Merge the two images.
* In english:
* Get $Image and $Watermark, and put them together.
* $PosX will return the right side of the image. And then substract 5px from it. So it isn't aligned to the right border.
* $PosY will do the same. Except this is the y axis. And will go to the bottom. And then 5px away from it.
* When you use both, it will return the corner. -5px of it. From both the bottom, and right side.
* Note that a image start at x: 0. y: 0, in the upper left corner.
* Set the size.x of $Watermark, and size.y too.
* Transparent: 25
*/
$PosX = imagesx($Image)-imagesx($Watermark)-5;
$PosY = imagesy($Image)-imagesy($Watermark)-5;
imagecopymerge($Image,$Watermark,$PosX,$PosY,0,0,imagesx($Watermark),imagesy($Watermark),25);

/* (X) And then generate our new image, as a png. */
imagepng($Image);

?>


That should be it!
If you have any questions. Feel free to ask me. I'll answer them! If I'm able to.
PhpFreak
Great first tutorial, keep it up.
Also, your English was perfect for me smile.gif
Xuxiix
QUOTE(PhpFreak @ Mar 18 2007, 07:44 PM) *
Great first tutorial, keep it up.
Also, your English was perfect for me smile.gif


Thank you. happy.gif
Dat
Providing any screenshots would be helpful how things are suppose to turn out.
Leibrockoli
Link to an example file might help.
krekas
Agree with Dar and Leibrockoli
Smashe
That's quiet simple - nice one smile.gif
The-Pixel
Great job.
Mr.Shawn
Looks interesting. Might give it a try.
N4Z.
Hey, i'm trying to learn PHP and tutorials like this don't really help, a tutorial is teaching someone, you have just supplied us with code... So i haven't learned a thing sad.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.