473,748 Members | 10,539 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ttransparent overlay watermark - on the fly?

Is it possible to overlay a transparent watermark on an image -
dynamically?
I'd like the result to look like this example:
<http://www.cycletouris t.com/temp/photo.php>

That is a bit of overkill, but you can see what I mean. The watermark
image (a png image) is included separately below the photo.

I tried using a class from phpclasses.org
<http://www.phpclasses. org/browse/package/1580.html...
but the result looks horrible. The transparency does not work.

I found one other method through Google,
<http://www.sitepoint.c om/article/watermark-images-php>
but it did not work, either.

Can this kind of transparent overlay be done on the fly with GD lib?

--
*************** **************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
*************** **************
Mar 19 '07 #1
9 5870
Chuck Anderson kirjoitti:
Is it possible to overlay a transparent watermark on an image -
dynamically?
I'd like the result to look like this example:
<http://www.cycletouris t.com/temp/photo.php>

That is a bit of overkill, but you can see what I mean. The watermark
image (a png image) is included separately below the photo.

I tried using a class from phpclasses.org
<http://www.phpclasses. org/browse/package/1580.html...
but the result looks horrible. The transparency does not work.

I found one other method through Google,
<http://www.sitepoint.c om/article/watermark-images-php>
but it did not work, either.

Can this kind of transparent overlay be done on the fly with GD lib?
Yeah, I've done this. What you do is you open image handles to both
files, the original image (imagecreatefro mjpg) and the png watermark
(imagecreatefro mpng), then combine them with either imagecopy,
imagecopyresamp led or some other imagecopy* function that works best for
you. Just go ahead and try them.

--
Ra*********@gma il.com
"Olemme apinoiden planeetalla."
Mar 19 '07 #2
Rami Elomaa schrieb:
Chuck Anderson kirjoitti:
>Is it possible to overlay a transparent watermark on an image -
dynamically?
Yeah, I've done this. What you do is you open image handles to both
files, the original image (imagecreatefro mjpg) and the png watermark
(imagecreatefro mpng), then combine them with either imagecopy,
imagecopyresamp led or some other imagecopy* function that works best for
you. Just go ahead and try them.
I've done one transparent overlay of two pictures, too, but found it a
bit tricky to do.

You have to be careful with using imagecopymerge. As i remember there is
a parameter to allow transparency to be used.

I wonder if different imagetypes can be used without any probs? Please
tell if you have tested it, i'm curious about it.

moido apinoiden planeetalta!
Mar 19 '07 #3
Message-ID: <Yt************ *************** ***@comcast.com from Chuck
Anderson contained the following:
>Can this kind of transparent overlay be done on the fly with GD lib?
Yep.

www.ckdog.co.uk/watermark
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Mar 20 '07 #4
j.***@web.de wrote:
Rami Elomaa schrieb:
>Chuck Anderson kirjoitti:
>>Is it possible to overlay a transparent watermark on an image -
dynamically ?

>Yeah, I've done this. What you do is you open image handles to both
files, the original image (imagecreatefro mjpg) and the png watermark
(imagecreatefr ompng), then combine them with either imagecopy,
imagecopyresam pled or some other imagecopy* function that works best for
you. Just go ahead and try them.

I've done one transparent overlay of two pictures, too, but found it a
bit tricky to do.

You have to be careful with using imagecopymerge. As i remember there is
a parameter to allow transparency to be used.

I wonder if different imagetypes can be used without any probs? Please
tell if you have tested it, i'm curious about it.

moido apinoiden planeetalta!
Okay, thanks for all the help. I see now that the imagecopy....
functions do what I need. The only one that lets you adjust the
transparency of the overlaying image, though, is imagecopymerge.

One big problem is that I am having no luck with using a png for the
overlay. There is a background color, not transparency.

I've added more to the example page.
<http://www.cycletouris t.com/temp/photo.php>

The top image is one I created in Paint Shop Pro by pasting the
transparent png over a photo image multiple times. I really like the
look of the transparency there.

The two gray boxes under the photo contain the png and gif images I am
using for the watermark. The background behind the watermark images is
set with CSS. The png version is 24 bit with alpha channel
transparency. The gif image had to be blended with some color so I
chose a light medium gray (which you can see on top of the background).
If you click on either of those you can see the respective Php generated
results.

Using a transparent gif for the watermark when generating the image with
Php looks shoddy in comparison to the one I made in Paint Shop Pro.

The png watermark is not even transparent ... and I don't know why. I
wonder if it would look better than the gif version, but I can't figure
out how to make it overlay and be transparent.

So, ... questions ....
1. Can I get results more like the image I created in Paint Shop Pro?
2. Why is the png not transparent when I use imagecopymerge (and will it
look better if I get it working)?

Here is the Php script I am using:

<?php
function display_with_wa termark($src, $dest, $png=0)
{
// use less than 100% opacity in imagecopymerge to improve the appearance
$pct = 70;

if ($png)
$watermark = imagecreatefrom png('cycletouri st_x2.png');
else
$watermark = imagecreatefrom gif('cycletouri st_x2.gif');

$watermark_widt h = imagesx($waterm ark);
$watermark_heig ht = imagesy($waterm ark);

$image = imagecreatetrue color($watermar k_width, $watermark_heig ht);
$image = imagecreatefrom jpeg($src);
$size = getimagesize($s rc);

// center the watermark
$dest_x = ($size[0] - $watermark_widt h)/2;
$dest_y = $size[1]/2 - $watermark_heig ht/2;

// lay it on 3 times - upper, middle, and lower
imagecopymerge( $image, $watermark, $dest_x, $dest_y, 0, 0,
$watermark_widt h, $watermark_heig ht, $pct);

imagecopymerge( $image, $watermark, $dest_x,
$dest_y/2 - $watermark_heig ht/2, 0, 0, $watermark_widt h,
$watermark_heig ht, $pct);

imagecopymerge( $image, $watermark, $dest_x,
($dest_y + $dest_y/2) + $watermark_heig ht/2, 0, 0,
$watermark_widt h, $watermark_heig ht, $pct);

header('Content-Type: image/jpg');
header('Content-Disposition: inline; filename=' . $src);

imagejpeg($imag e);
imagedestroy($i mage);
imagedestroy($w atermark);
}

$src = '../Scenes/St_Peters_Basil ica.jpg';

display_with_wa termark($src, $dest, 0); // 0 = gif watermark, 1 = png
?>

--
*************** **************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
*************** **************
Mar 20 '07 #5
j.***@web.de kirjoitti:
Rami Elomaa schrieb:
>Chuck Anderson kirjoitti:
>>Is it possible to overlay a transparent watermark on an image -
dynamically ?
>Yeah, I've done this. What you do is you open image handles to both
files, the original image (imagecreatefro mjpg) and the png watermark
(imagecreatefr ompng), then combine them with either imagecopy,
imagecopyresam pled or some other imagecopy* function that works best
for you. Just go ahead and try them.

I've done one transparent overlay of two pictures, too, but found it a
bit tricky to do.

You have to be careful with using imagecopymerge. As i remember there is
a parameter to allow transparency to be used.

I wonder if different imagetypes can be used without any probs? Please
tell if you have tested it, i'm curious about it.
Now I have to admit that it was over 4 years ago since I did the whole
watermarking thing, so I can't say I'm SURE it worked, but I don't
remember having any problems with it. It was just like I said: open two
image handles, one jpg, one png, then place the png on the jpg with
imagecopyresize d. I found the original script I used back then and it
seemed very simple to begin with. I suppose I'd have to do some testing
with the script to see if it indeed worked like I'm thinking it did.

--
Ra*********@gma il.com
"Olemme apinoiden planeetalla."
Mar 20 '07 #6
Chuck Anderson wrote:
j.***@web.de wrote:
>Rami Elomaa schrieb:

>>Chuck Anderson kirjoitti:
Is it possible to overlay a transparent watermark on an image -
dynamicall y?


>>Yeah, I've done this. What you do is you open image handles to both
files, the original image (imagecreatefro mjpg) and the png watermark
(imagecreatef rompng), then combine them with either imagecopy,
imagecopyresa mpled or some other imagecopy* function that works best for
you. Just go ahead and try them.

I've done one transparent overlay of two pictures, too, but found it a
bit tricky to do.

You have to be careful with using imagecopymerge. As i remember there is
a parameter to allow transparency to be used
>.....

Okay, thanks for all the help. I see now that the imagecopy....
functions do what I need. The only one that lets you adjust the
transparency of the overlaying image, though, is imagecopymerge.

One big problem is that I am having no luck with using a png for the
overlay. There is a background color, not transparency.

I've added more to the example page.
<http://www.cycletouris t.com/temp/photo.php>

The top image is one I created in Paint Shop Pro by pasting the
transparent png over a photo image multiple times. I really like the
look of the transparency there.

The two gray boxes under the photo contain the png and gif images I am
using for the watermark. The background behind the watermark images is
set with CSS. The png version is 24 bit with alpha channel
transparency. The gif image had to be blended with some color so I
chose a light medium gray (which you can see on top of the background).
If you click on either of those you can see the respective Php generated
results.

.....
So, ... questions ....
1. Can I get results more like the image I created in Paint Shop Pro?
2. Why is the png not transparent when I use imagecopymerge (and will it
look better if I get it working)?
[previous script deleted]
Okay, I finally found the answer(s) I needed to make this work.

First. For the watermark, you must use a 24 bit png (not 8 bit) - and
the best results, by far, are with alpha transparency. (A transparent
gif watermark works, but a transparent png produces much better quality.)

Second - Do *not* use imagecopymerge (with a transparent png
watermark). It "destroys" the transparency in the png. I chose
imagecopyresamp led because I want to re-size the watermark to fit the
image, and this produces better results than imagecopyresize d.

My new results are here - in the old same place:
http://www.cycletourist.com/temp/photo.php

--
*************** **************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
*************** **************
Mar 22 '07 #7
Message-ID: <5_************ *************** ***@comcast.com from Chuck
Anderson contained the following:
>Okay, I finally found the answer(s) I needed to make this work.

First. For the watermark, you must use a 24 bit png (not 8 bit) - and
the best results, by far, are with alpha transparency. (A transparent
gif watermark works, but a transparent png produces much better quality.)

Second - Do *not* use imagecopymerge (with a transparent png
watermark). It "destroys" the transparency in the png. I chose
imagecopyresam pled because I want to re-size the watermark to fit the
image, and this produces better results than imagecopyresize d.
Have you got some sample code?

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Mar 23 '07 #8
Geoff Berrow wrote:
Message-ID: <5_************ *************** ***@comcast.com from Chuck
Anderson contained the following:

>Okay, I finally found the answer(s) I needed to make this work.

First. For the watermark, you must use a 24 bit png (not 8 bit) - and
the best results, by far, are with alpha transparency. (A transparent
gif watermark works, but a transparent png produces much better quality.)

Second - Do *not* use imagecopymerge (with a transparent png
watermark). It "destroys" the transparency in the png. I chose
imagecopyresam pled because I want to re-size the watermark to fit the
image, and this produces better results than imagecopyresize d.

Have you got some sample code?

Sure. I have not taken the size of the src image into account yet. This
example was a test of concept. I also want to rotate the watermark, but
here's how it is now. I started with the code from here:
<http://www.sitepoint.c om/article/watermark-images-php... and reworked
some parts.

display_with_wa termark.php
usage:
<img src="display_wi th_watermark.ph p?src=<?php echo
$path_to_source _image ?>">

<?php
$src = $_GET['src'];

// my watermark image is a 24 bit png with alpha channel transparency
$watermark = imagecreatefrom png('your_water mark_image.png' );

$watermark_widt h = imagesx($waterm ark);
$watermark_heig ht = imagesy($waterm ark);

$image = imagecreatetrue color($watermar k_width, $watermark_heig ht);
$image = imagecreatefrom jpeg($src);
$size = getimagesize($s rc);

// center in source image
$dest_x = ($size[0] - $watermark_widt h)/2;
$dest_y = $size[1]/2 - $watermark_heig ht/2;

// place in top third of image
imagecopyresamp led($image, $watermark, $dest_x,
$dest_y/2 - $watermark_heig ht/2, 0, 0, $watermark_widt h,
$watermark_heig ht, $watermark_widt h, $watermark_heig ht);

// centerd and half sized
imagecopyresamp led($image, $watermark,
$dest_x + $watermark_widt h/4, $dest_y + $watermark_heig ht/4,
0, 0, $watermark_widt h/2, $watermark_heig ht/2,
$watermark_widt h, $watermark_heig ht);

// place in bottom third
imagecopyresamp led($image, $watermark, $dest_x,
$dest_y + $dest_y/2 + $watermark_heig ht/2, 0, 0,
$watermark_widt h, $watermark_heig ht, $watermark_widt h,
$watermark_heig ht);

header('Content-Type: image/jpg');
header('Content-Disposition: inline; filename=' . $src);

imagejpeg($imag e);

imagedestroy($i mage);
imagedestroy($w atermark);
?>

--
*************** **************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
*************** **************
Mar 23 '07 #9
Message-ID: <39************ *************** ***@comcast.com from Chuck
Anderson contained the following:
>Have you got some sample code?


Sure. I have not taken the size of the src image into account yet. This
example was a test of concept. I also want to rotate the watermark, but
here's how it is now. I started with the code from here:
<http://www.sitepoint.c om/article/watermark-images-php... and reworked
some parts.
Thanks. My watermark script works fine but it's slow.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Mar 23 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1649
by: Thomas | last post by:
I've searched google for this topic and found a few examples, but I need an example of how to create a semi-transparent, non-intrusive watermark for images using PIL, something that takes into account the background of the image when choosing color for the text. Making a huge white box or just putting a single-color text across the entire image looks just bad, so if there is a way to create a more professional looking watermark I'd be...
2
2061
by: export | last post by:
Is there a way how to put a watermark on images by using Python? Lad.
2
4961
by: tvmaly | last post by:
I have been trying to add a watermark to a jpeg using PIL, but the watermark has a black box around it. I looked at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362879 and http://mail.python.org/pipermail/python-list/1999-May/003369.html but I think these only refer to gif or png. I know jpegs really do not
0
5676
by: Never Best | last post by:
I'm having troubles attaching the Device to a window using its hWnd, and I have some troubles with getting transparancy to work with a DDOverlay... if anyone could help it would be greatlay appreasated. Here is some of my code. The Transparancy isn't working because the ColorSpaceLow/HighValue isn't set... The Line" overFX.DestinationColorKey.ColorSpaceLowValue = Color.White" returns the error "Cannot Modify the return value because it...
1
2192
by: m3ckon | last post by:
I have a requirement for a new website to create an image based web site. The site needs to have an administration area where admin can upload images to be displayed on the site. These images need to be resized and then given a watermark. My question is how do you add a watermark to an image??? M3ckon
0
2212
by: =?Utf-8?B?S2Vycnk=?= | last post by:
Hi all -- I am a long-time C programmer and "medium-time" C++ programmer, but am brand new to C#. I am creating a simple app using C# and I need help. The app will display a "watermark" on the screen at certain times. When the watermark is visible, it will be on top of all other applications. To get the look I wanted, I created a simple form, imported a bitmap image as the background to the form, and set the opacity to 15%. I set...
2
3287
by: pravinnweb | last post by:
i have dropdown select menu in my page. when i click any button the black overlay comes while loading. in FF overlay working fine but in IE the select option menu appeared on overlay...please help me
5
3872
by: pravinnweb | last post by:
i have dropdown select menu in my page. when i click here link the black overlay comes .in FF overlay working fine but in IE6 the select option menu appeared on overlay...please help me thanks in advance! here is the code <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>LIGHTBOX EXAMPLE</title>
1
1716
by: rfr | last post by:
Apparently the Transitional Doctype kills this script because the script does not make proper use of units like "px". It works well without a doctype statement. But once someone adds a transitional doctype, the js script no longer works. Can someone familiar with javascript bring it up-to-date so that it works with current doctypes and post it here for others to make use of? The whole HTML document including the js scrip follows (...
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9325
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8244
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.