This code will allow you to tile watermark an image.
I was working on a project called Spark Lemon while producing this, so if you use the code in this example, thats where the image derived from.
Hope you find it useful, also Please do NOT use the smart lemon logo as the tile, as it is obviously copyritten.
[syntax=php]
<?php
function add_watermark($image) {
$overlay = 'http://sparklemon.com/php/watermark.png';
$w_offset = 0;
$h_offset = 0;
$extension = strtolower(substr($image, strrpos($image, ".") +1));
switch ($extension)
{
case 'jpg':
$background = imagecreatefromjpeg($image);
break;
case 'jpeg':
$background = imagecreatefromjpeg($image);
break;
case 'png':
$background = imagecreatefrompng($image);
break;
default:
die("Image type not supported");
}
$base_width = imagesx($background);
$base_height = imagesy($background);
imagealphablending($background, true);
$overlay = imagecreatefrompng($overlay);
imagesettile($background, $overlay);
// Make the image repeat
imagefilledrectangle($background, 0, 0, $base_width, $base_height, IMG_COLOR_TILED);
header('Content-type: image/png');
imagepng($background);
}
echo add_watermark('http://c360958.r58.cf2.rackcdn.com/68313_ca68f6cf457ae3950ff96880c6296d18.jpg');
?>
[/syntax]
EDIT: the final image (http://c360958.r58.cf2.rackcdn.com/6831 ... 296d18.jpg) is from my game currently in development, I own all graphics within that document, so please do not replicate or reproduce. Thank you
Watermark an Image
-
- Posts: 534
- Joined: Thu May 05, 2011 8:19 pm
Watermark an Image
Last edited by jacek on Thu May 05, 2011 8:35 pm, edited 2 times in total.
Reason: syntax tags
Reason: syntax tags
I don't like to brag, but I wasn't circumcised. I was circumnavigated.
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Re: Watermark an Image
This looks really nice, so if i was to have a image hosting website i could add this code and it add a watermark to all the images?
-
- Posts: 534
- Joined: Thu May 05, 2011 8:19 pm
Re: Watermark an Image
wignall6 wrote:This looks really nice, so if i was to have a image hosting website i could add this code and it add a watermark to all the images?
Yes, that is a purpose of something like this.
You would call the function on the image that was uploaded, and then save that new image to overwrite the old one.
I don't like to brag, but I wasn't circumcised. I was circumnavigated.
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Re: Watermark an Image
To be a pain: can you use the syntax buttons when posting code, as that’s what XHBB will eventually use for code.
also, this looks good
also, this looks good
Re: Watermark an Image
This will be a great addion to my website, thanks very much!