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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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); |
|
|||
|
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/ |
![]() |
| Thread Tools | |
| Display Modes | |
|
|