View Full Version : Image Automatic Watermarking.
killerchutney
03-19-2007, 08:24 PM
Hi, Does anyone know of any free Automatic image watermarking that I can implement into a image uploading script.
Thanks.
mburt
03-19-2007, 08:26 PM
Use CSS:
background:url('myimage.jpg') no-repeat fixed top left;
If you want to give it a "watermark" effect, use an image-editing program.
killerchutney
03-19-2007, 08:29 PM
Thanks for quick reply but is it possible for PHP to get an image, put a watermark over it so its only one image. I think it is because PHP can create captcha codes on the fly.
mburt
03-19-2007, 08:35 PM
Look in the php.net manual (image functions):
http://ca3.php.net/manual/en/ref.image.php
boxxertrumps
03-19-2007, 08:37 PM
GD library.
http://www.phpfreaks.com/tutorials/105/0.php
djr33
03-19-2007, 11:22 PM
You should be able to combine two images fairly easily.
Create a loop that runs through all of the pixels, then for each that is white in the watermark image, make the pixel of the main image a blend of the watermark pixel and image pixel. If black, leave as is. Or any variation you want.
Basically, something like--
<?php
$imgurl = $_GET['img'];
$image=imageCreateFromJPEG($imgurl);
//or create your image from upload
$imagewidth = imagesx($image);
$imageheight = imagesy($image);
//get dimensions
$watermarkurl = $_GET['wm'];
$watermark=imageCreateFromGIF($watermarkurl);
//as above, do what you want for getting the watermark
$wmwidth = imagesx($watermark);
$wmheight = imagesy($watermark);
//get dimensions of watermark
imagecopyresampled($watermark, $watermark, 0, 0, 0, 0, $imagewidth, $imageheight, $wmwidth, $wmheight);
//resize the watermark to be in the same dimensions as the image
for ($y = 0; $y < $imageheight; $y++) {
for ($x = 0; $x < $imagewidth; $x++) {
$imgcolor = imagecolorat($image,$x,$y);
$imgcolorrgb = imagecolorsforindex($image,$imgcolor);
$ir = $imgcolorrgb['red'];
$ig = $imgcolorrgb['green'];
$ib = $imgcolorrgb['blue'];
$wmcolor = imagecolorat($watermark,$x,$y);
$wmcolorrgb = imagecolorsforindex($watermark,$wmcolor);
$wr = $wmcolorrgb['red'];
$wg = $wmcolorrgb['green'];
$wb = $wmcolorrgb['blue'];
if ($ir<$wr&&$ig<$wg&&$ib<$wb) {
$pxcolor = imagecolorallocate($image, ($ir+$wr)/2, ($ig+$wg)/2, ($ib+$wb)/2);
imagesetpixel($image, $x, $y, $pxcolor);
}
}
}
//loop through image
//and set pixel to white
//if wm is white at pixel
header("Content-type: image/jpg");
imagejpeg($image);
imagedestroy($image);
//output
?>
boxxertrumps
03-19-2007, 11:36 PM
Does gd library support layers?
if so, a semitransperent png ontop of the watermarked picture would be the best option.
djr33
03-19-2007, 11:47 PM
Its support for layers is annoying and not very trustworthy.
Anyway, I've been testing, and here's the result:
http://ci-pro.com/misc/phptest/images/watermark.php?img=http://www.huddletogether.com/projects/lightbox/images/image-1.jpg&wm=http://www.informika.ru/text/magaz/higher/Image25.gif
From two random sources:
http://www.huddletogether.com/projects/lightbox/images/image-1.jpg
http://www.informika.ru/text/magaz/higher/Image25.gif
Note: The code in the last post is updated to reflect changes I made.
tech_support
03-20-2007, 12:02 AM
It's a bit laggy though.
djr33
03-20-2007, 12:06 AM
Sure. It's running through every pixel.
This is for watermarking on upload, so it shouldn't be an issue.
Write a faster script if you question this :D
...PHP is slow with images, but I have yet to find a way around that.
tech_support
03-20-2007, 05:51 AM
Ok.
Total Page Processing Time: 15.453 seconds.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.