stsleeper94 Posted March 18, 2008 Share Posted March 18, 2008 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 More sharing options...
conker87 Posted March 18, 2008 Share Posted March 18, 2008 You could use $_GET with the name of the image file in the variable. $image = imagecreatefromjpeg($_GET['image'] . ".jpg"); Link to comment https://forums.phpfreaks.com/topic/96722-redirected-watermarking/#findComment-494925 Share on other sites More sharing options...
stsleeper94 Posted March 18, 2008 Author Share Posted March 18, 2008 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 Link to comment https://forums.phpfreaks.com/topic/96722-redirected-watermarking/#findComment-494989 Share on other sites More sharing options...
conker87 Posted March 18, 2008 Share Posted March 18, 2008 <?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) Link to comment https://forums.phpfreaks.com/topic/96722-redirected-watermarking/#findComment-494999 Share on other sites More sharing options...
stsleeper94 Posted March 18, 2008 Author Share Posted March 18, 2008 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. Link to comment https://forums.phpfreaks.com/topic/96722-redirected-watermarking/#findComment-495012 Share on other sites More sharing options...
BlueSkyIS Posted March 18, 2008 Share Posted March 18, 2008 i'd use the path so your code is more portable. maybe it's here: $image_directory = $_SERVER['DOCUMENT_ROOT']."/images/collections/albums/"; Link to comment https://forums.phpfreaks.com/topic/96722-redirected-watermarking/#findComment-495018 Share on other sites More sharing options...
conker87 Posted March 18, 2008 Share Posted March 18, 2008 You do either. Do what BlueSkyIs says (which I recommend) or point your mod_rewrite script to the watermark.php in the image directory. For the sake of having all your scripts in one folder, I'd go for the way clear sky says. Link to comment https://forums.phpfreaks.com/topic/96722-redirected-watermarking/#findComment-495026 Share on other sites More sharing options...
stsleeper94 Posted March 18, 2008 Author Share Posted March 18, 2008 <?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? Link to comment https://forums.phpfreaks.com/topic/96722-redirected-watermarking/#findComment-495063 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.