watermarking pictures on server
11-26-2008, 08:01 AM
|
watermarking pictures on server
|
Posts: 21
|
I have had a few instances of people stealing photo's / images from my website.
I believe that you can somehow watermark all the images on a site using a script?
Can someone please point me in the right direction?
Thanks in advance
|
|
|
|
11-27-2008, 08:37 PM
|
Re: watermarking pictures on server
|
Posts: 21,624
Location: Blackpool. UK
|
In what server side code?
|
|
|
|
11-27-2008, 08:45 PM
|
Re: watermarking pictures on server
|
Posts: 21
|
Don't know Chris
I have a dedicated server, but I don't know much about the way it works or the scripts.
I've seen some photo websites- where you have to pay for the images and they seem to have something that puts a watermark infront of all images. I did read something about doing it through .htaccess but I'm not sure what to do
It would be good if I could just put a script or code on the server.
I'm not bothered if I have to pay for it.
|
|
|
|
11-27-2008, 09:02 PM
|
Re: watermarking pictures on server
|
Posts: 21,624
Location: Blackpool. UK
|
It's Apache 2 with PHP 5.2.5
ImageMagick or GD on the server will get you watermarking.
|
|
|
|
11-28-2008, 06:37 AM
|
Re: watermarking pictures on server
|
Posts: 21
|
Thanks Chris,
Both of those are way past my knowledge, I am afraid
I'd have to get someone to install it for me or find something else.
|
|
|
|
11-28-2008, 06:49 AM
|
Re: watermarking pictures on server
|
Posts: 3,139
Name: Thierry
Location: I'm the uber Spaminator !
|
:-)
No bashing, but I find funny that your username being "DIY", yo need someone else.
Question: Do you use a web interface to upload the pictures and need them to be watermarked at upload time, or do you need to mass-watermark existing pics?
__________________
Only a biker knows why a dog sticks his head out the window.
|
|
|
|
11-28-2008, 07:15 AM
|
Re: watermarking pictures on server
|
Posts: 21
|
Quote:
Originally Posted by tripy
:-)
No bashing, but I find funny that your username being "DIY", yo need someone else.
Question: Do you use a web interface to upload the pictures and need them to be watermarked at upload time, or do you need to mass-watermark existing pics?
|
Well that is exactly why I am called DIY- i'm great at diy, but not good at webmastering, I just don't have the nerdy gene lol
I need to mass watermark existing pics.
|
|
|
|
11-28-2008, 07:29 AM
|
Re: watermarking pictures on server
|
Posts: 3,139
Name: Thierry
Location: I'm the uber Spaminator !
|
Ok, in that case, I have what you need...
I've played with python and image manipulation a bit, some times ago. One time I've played with was the watermarking.
For that program to run, you need to install Python 2.5 or 2.6 and PIL (Python Image Library) corresponding to your python version.
Here is the code:
wm.py
Code:
import Image, ImageEnhance, sys
'''
wm.py
Watermarking of a given picture with alpha-blending the mask
'''
def reduce_opacity(im, opacity):
"""Returns an image with reduced opacity."""
assert opacity >= 0 and opacity <= 1
if im.mode != 'RGBA':
im = im.convert('RGBA')
else:
im = im.copy()
alpha = im.split()[3]
alpha = ImageEnhance.Brightness(alpha).enhance(opacity)
im.putalpha(alpha)
return im
def watermark(im, mark, position, opacity=1):
"""Adds a watermark to an image."""
if opacity < 1:
mark = reduce_opacity(mark, opacity)
if im.mode != 'RGBA':
im = im.convert('RGBA')
# create a transparent layer the size of the image and draw the
# watermark in that layer.
layer = Image.new('RGBA', im.size, (0,0,0,0))
if position == 'tile':
for y in range(0, im.size[1], mark.size[1]):
for x in range(0, im.size[0], mark.size[0]):
layer.paste(mark, (x, y))
elif position == 'scale':
# scale, but preserve the aspect ratio
ratio = min(
float(im.size[0]) / mark.size[0], float(im.size[1]) / mark.size[1])
w = int(mark.size[0] * ratio)
h = int(mark.size[1] * ratio)
mark = mark.resize((w, h))
layer.paste(mark, ((im.size[0] - w) / 2, (im.size[1] - h) / 2))
else:
#place the watermark once, at the coordinate given by "position"
w=position[0]
h=position[1]
if w<0:
w=im.size[0] - w - mark.size[0] - 10
if h<0:
h=im.size[1] - h - mark.size[1] - 10
layer.paste(mark, (w, h))
# composite the watermark with the layer
ret=Image.composite(layer, im, layer)
return ret
def GoForIt(src, msk, opacity, save=None,):
im = Image.open(src)
mark = Image.open(msk)
#img=watermark(im, mark, 'tile', 0.15).show()
#img=watermark(im, mark, 'scale', 0.15).show()
img=watermark(im, mark, (-10, -10), opacity)
if save==None:
img.show()
else:
img.save(save)
if __name__ == '__main__':
if len(sys.argv)==5:
src=str(sys.argv[1])
msk=str(sys.argv[2])
opacity=float(sys.argv[3])
save=str(sys.argv[4])
else:
src='test.png'
msk='watermark.png'
opacity=0.5
print>>sys.stdout, 'Usage: %s src_image watermark opacity (0<0.5>1) save_file\n\tsrc_image:\t image to watermark\n\twm_image:\tThe watermark\n\topacity:\tA float value between 0 and 1. O means invisible, 1 means completly solid\n\tsave_file:\t The name of the file to be created. If none given, the watermark image is shown, but not saved'%(sys.argv[0])
GoForIt(src, msk, opacity, save)
Now, once you have installed support for python and pil, save this script.
Considering that you have your watermark and your script in 1 directory, and the images to watermark in another directory named "pics", and you want your watermarked images in an "wm" directory, you need to type:
Code:
for i in pics/;do python script.py '$i' 'watermark.png' 0.15 'wm/$i';done
This means: for each files in the directory "pics", call script.py with that file and the watermark "watermark.png", apply it with an alpha-blending of 0.15 on the lower right corner and save the resulting image with the same name as the original in the "wm" folder.
This is a bash shell syntax though. It's the default shell on many linux/bsd distributions. If your server is running windows, it won't work.
Given this image:
and this watermark:
The result is:

__________________
Only a biker knows why a dog sticks his head out the window.
Last edited by tripy; 11-28-2008 at 07:36 AM..
|
|
|
|
11-28-2008, 07:55 AM
|
Re: watermarking pictures on server
|
Posts: 21
|
Thanks for the reply tripy,
Something like that would be great, but would it be possible to make the watermark appear in the centre?
Here is what I would prefer if possible-
I have made the watermark green then it is easy to see.
The reason I don't want the watermark on the bottom right is that it is easy to cut off the watermark.
|
|
|
|
11-28-2008, 08:15 AM
|
Re: watermarking pictures on server
|
Posts: 3,139
Name: Thierry
Location: I'm the uber Spaminator !
|
Yes, it's feasable, of course.
In fact, the script has 3 watermarking rendering.
The watermark is scaled all over the image, it's repeated or it's placed in 1 particular place.
You already have seen the position. The other results are
scaled:
tile:
Ok, so, I've just hacked my script for
1) add an "centered" mode
2) you can specify the mode on call time now
This is the revised script:
Code:
import Image, ImageEnhance, sys
'''
wm.py
Watermarking of a given picture with alpha-blending the mask
'''
def reduce_opacity(im, opacity):
"""Returns an image with reduced opacity."""
assert opacity >= 0 and opacity <= 1
if im.mode != 'RGBA':
im = im.convert('RGBA')
else:
im = im.copy()
alpha = im.split()[3]
alpha = ImageEnhance.Brightness(alpha).enhance(opacity)
im.putalpha(alpha)
return im
def watermark(im, mark, position, opacity=1):
"""Adds a watermark to an image."""
if opacity < 1:
mark = reduce_opacity(mark, opacity)
if im.mode != 'RGBA':
im = im.convert('RGBA')
# create a transparent layer the size of the image and draw the
# watermark in that layer.
layer = Image.new('RGBA', im.size, (0,0,0,0))
if position == 'tile':
for y in range(0, im.size[1], mark.size[1]):
for x in range(0, im.size[0], mark.size[0]):
layer.paste(mark, (x, y))
elif position == 'scale':
# scale, but preserve the aspect ratio
ratio = min(
float(im.size[0]) / mark.size[0], float(im.size[1]) / mark.size[1])
w = int(mark.size[0] * ratio)
h = int(mark.size[1] * ratio)
mark = mark.resize((w, h))
layer.paste(mark, ((im.size[0] - w) / 2, (im.size[1] - h) / 2))
elif position=='center':
(ww, wh)=mark.size
(iw, ih)=im.size
x=(iw/2)-(ww/2)
y=(ih/2)-(ww/2)
layer.paste(mark, (x, y))
else:
#place the watermark once, at the coordinate given by "position"
w=position[0]
h=position[1]
if w<0:
w=im.size[0] - w - mark.size[0] - 10
if h<0:
h=im.size[1] - h - mark.size[1] - 10
layer.paste(mark, (w, h))
# composite the watermark with the layer
ret=Image.composite(layer, im, layer)
return ret
def GoForIt(src, msk, opacity, save=None, mode='center'):
im = Image.open(src)
mark = Image.open(msk)
#img=watermark(im, mark, (-10, -10), opacity)
if mode=='center':
img=watermark(im, mark, 'center', opacity)
elif mode=='scale':
img=watermark(im, mark, 'scale', opacity)
elif mode=='tile':
img=watermark(im, mark, 'tile', opacity)
else:
img=watermark(im, mark, position, opacity)
if save==None:
img.show()
else:
img.save(save)
if __name__ == '__main__':
if len(sys.argv)==6:
src=str(sys.argv[1])
msk=str(sys.argv[2])
opacity=float(sys.argv[3])
save=str(sys.argv[4])
mode=str(sys.argv[5])
else:
src='test.png'
msk='watermark.png'
opacity=0.5
mode='center'
save=None
print>>sys.stdout, 'Usage: %s src_image watermark opacity (0<0.5>1) save_file\n\tsrc_image:\t image to watermark\n\twm_image:\tThe watermark\n\topacity:\tA float value between 0 and 1. O means invisible, 1 means completly solid\n\tsave_file:\t The name of the file to be created. If none given, the watermark image is shown, but not saved\n\tmode:\twatermarking mode. Can be "center", "tile", "scale" or an absolute position couple like this:"(-10,-10)" '%(sys.argv[0])
GoForIt(src, msk, opacity, save, mode)
And the calling bash script would be:
Code:
for i in pics/;do python script.py '$i' 'watermark.png' 0.15 'wm/$i' 'center';done
Which would result in

__________________
Only a biker knows why a dog sticks his head out the window.
Last edited by tripy; 11-28-2008 at 08:16 AM..
|
|
|
|
|
« Reply to watermarking pictures on server
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|