[Q] Overlay watermark on JPG

This is a discussion on [Q] Overlay watermark on JPG within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I managed to find some inline code to combine 2 images into 1. I want to use this to add ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-03-2005
Sir Loin of Beef
 
Posts: n/a
Default [Q] Overlay watermark on JPG

I managed to find some inline code to combine 2 images into 1. I want
to use this to add a watermark to my images.

However, the problem is that this is inline. I have a html page with a
number of links to different files, and I want each link to link to a
different image, while using the same watermark for all.

How can I do this?


Here's the basic code I found:

// The header line informs the server of what to send the output
// as. In this case, the server will see the output as a .png
// image and send it as such

header ("Content-type: image/png");


// Defining the background image. Optionally, a .jpg image could
// could be used using imagecreatefromjpeg, but I personally
// prefer working with png

$background = imagecreatefrompng("backgroundimage.png");


// Defining the overlay image to be added or combined.

$insert = imagecreatefrompng("overlay.png");


// Select the first pixel of the overlay image (at 0,0) and use
// it's color to define the transparent color

imagecolortransparent($insert,imagecolorat($insert ,0,0));


// Get overlay image width and hight for later use

$insert_x = imagesx($insert);
$insert_y = imagesy($insert);


// Combine the images into a single output image. Some people
// prefer to use the imagecopy() function, but more often than
// not, it sometimes does not work. (could be a bug)

imagecopymerge($background,$insert,0,0,0,0,$insert _x,$insert_y,100);


// Output the results as a png image, to be sent to viewer's
// browser. The results can be displayed within an HTML document
// as an image tag or background image for the document, tables,
// or anywhere an image URL may be acceptable.

imagepng($background,"",100);
Reply With Quote
  #2 (permalink)  
Old 02-03-2005
Dave Patton
 
Posts: n/a
Default Re: [Q] Overlay watermark on JPG

test@gesg.com (Sir Loin of Beef) wrote in
news:4202202d.4707583@news.starhub.net.sg:

> I managed to find some inline code to combine 2 images into 1. I want
> to use this to add a watermark to my images.
>
> However, the problem is that this is inline. I have a html page with a
> number of links to different files, and I want each link to link to a
> different image, while using the same watermark for all.
>
> How can I do this?


First, create a PHP script that will take one of
your existing images(you can hardcode the name
during development) and output it as a new image
with the watermark included. For example, if
you called it watermark_my_image.php, then
http://www.example.com/watermark_my_image.php
would return an image. You need to output only
the image(any PHP errors will mess things up),
and include the appropriate HTTP headers, via
the use of header().

Once that's working, devise some method whereby
you can tell watermark_my_image.php what image
to use, rather than having it hardcoded. One
obvious choice is via the URL query string.

Then, change your HTML page with the existing
image tags to use your PHP script. For example,
<img src="image1.png" alt=""> gets changed to:
<img src="watermark_my_image.php?image=image1.png"
alt="">

You could move "image1.png" and the other images
to a folder outside the webserver's document root
tree so that people cannot access the images
directly, but have to use watermark_my_image.php

--
Dave Patton
Canadian Coordinator, Degree Confluence Project
http://www.confluence.org/
My website: http://members.shaw.ca/davepatton/
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:33 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0