Jump to content

Redirected Watermarking


stsleeper94

Recommended Posts

I am using

<?php  

header('Content-Type: image/jpeg');  
$wm = imagecreatefrompng('watermark.png');
//get dimensions
$h = imagesy($wm);
$w = imagesx($wm);
//load image to be watermarked
$image = imagecreatefromjpeg('image.jpg');
$offset = 10;
$x = imagesx($image) - ($w+$offset);
$y = imagesy($image) - ($h+$offset);
//merges them
imagecopymerge($image, $wm, $x, $y, 0, 0, $w, $h, 100);
imagejpeg($image);
//clear memory
imagedestroy($image);
imagedestroy($wm);
?>

 

To watermark  image at a time (image.jpg).  I would like to change this so that whenever a picture is clicked to view fullsize mod rewrite passes it through the above code (modified of course) and outputs any image requested.  How do I rewrite $image = imagecreatefromjpeg('image.jpg'); to represent "any" image clicked.

 

My mod write has been checked and points to here, and I know the above will not do anyfile, so I was wondering how I would go about doing that.

 

THanks

Link to comment
https://forums.phpfreaks.com/topic/96722-redirected-watermarking/
Share on other sites

How would I test this code, without using the mod - rewrite.  I guess I mean, what is the path I use to see if it will actually  watermark the picture, so I can isolate any issue that could occur.  Before I would just type

mywesite.com/images/image.jpg with the get, I am telling it to use what I give it so how do I name that in the path to make sure everything is okay? before I start muddling in the mod rewrite. 

 

http://mywebsite/images/watermark.php?img=image.jpg  Does not currently show me anything?  I want the previous to be how my php will call all the photos, if possible.

 

 

 

Also by declaring it 'image' what if my next photo is called photo.jpg?  Will this Get function still work?g

<?php  

header('Content-Type: image/jpeg');  
$wm = imagecreatefrompng('watermark.png');
//get dimensions
$h = imagesy($wm);
$w = imagesx($wm);
//load image to be watermarked
$image = imagecreatefromjpeg($_GET['img'] . ".jpg");
$offset = 10;
$x = imagesx($image) - ($w+$offset);
$y = imagesy($image) - ($h+$offset);
//merges them
imagecopymerge($image, $wm, $x, $y, 0, 0, $w, $h, 100);
imagejpeg($image);
//clear memory
imagedestroy($image);
imagedestroy($wm);
?>

And the url would be:

http://site.com/yourpathto/imagedir/watermark.php?img=image (without the .jpg, since you already have it in your code)

Awesome, I was just about to make an edit that I was progressing with this then I saw your response.  Well done.  Still I need to understand this last piece.  For this test.  image.jpg was just in the image folder with the watermark.php

 

All of my files however exist in a folder : images/collections/albums/

 

Do I move the watermark and the php to the albums folder where all my pics are or do I add a path variable?  Eventually I may have more folders but for now I will just use the ones in albums as my testing grounds.

<?php  

header('Content-Type: image/jpeg');  
$wm = imagecreatefrompng('watermark.png');
//get dimensions
$h = imagesy($wm);
$w = imagesx($wm);
//load image to be watermarked
$image_directory = $_SERVER['DOCUMENT_ROOT']."/images/plogger_test_collection/plogger_test_album";
$image = imagecreatefromjpeg($_GET['img'] . ".jpg");
$offset = 10;
$x = imagesx($image) - ($w+$offset);
$y = imagesy($image) - ($h+$offset);
//merges them
imagecopymerge($image, $wm, $x, $y, 0, 0, $w, $h, 100);
imagejpeg($image);
//clear memory
imagedestroy($image);
imagedestroy($wm);
?>

 

but at maysite.com/images/watermark.php?img=2005_0831_r001s05 the picture does not show?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.