sdi-graphics Posted December 29, 2010 Share Posted December 29, 2010 Hi I use this watermark script on my site and works great. http://www.sdi-graphics.com I wonder if it is possible to ad code so the watermark image I use re-sizes to 30 or 25 % of the image. My vendors upload images in different sizes and this would take care of the problem. Is this possible? I don't know php. Create a watermark named watermark.png and place it in the admin/ directory along with the watermark_wrapper.php file below. <?php // watermark_wrapper.php // Path the the requested file $path = $_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI']; // Load the requested image $image = imagecreatefromstring(file_get_contents($path)); $w = imagesx($image); $h = imagesy($image); // Load the watermark image $watermark = imagecreatefrompng('watermark.png'); $ww = imagesx($watermark); $wh = imagesy($watermark); // Merge watermark upon the original image imagecopy($image, $watermark, $w-$ww, $h-$wh, 0, 0, $ww, $wh); // Send the image header('Content-type: image/jpeg'); imagejpeg($image); exit(); ?> Next you will need to create a .htaccess file in the image/ directory with the following: RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f RewriteRule \.(gif|jpeg|jpg|png)$ /admin/watermark_wrapper.php [QSA,NC] Any help appreciated. Wolfgang Quote Link to comment https://forums.phpfreaks.com/topic/222926-watermark-script/ Share on other sites More sharing options...
hackalive Posted December 30, 2010 Share Posted December 30, 2010 Looking here: http://articles.sitepoint.com/article/watermark-images-php If you got the image dimensions (http://php.net/manual/en/function.getimagesize.php) and then used the formula: percentage(as a decimal)/imageheight = $y ........ e.g. 0.5/1000 = 500 percentage(as a decimal)/imagewidth = $x ........ e.g. 0.5/1000 = 500 then apparently $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); places the watermark over the whole image ... so just adjust $watermark to refelt $x or $y. Give that ago, without watermark_wrapper.php (all the code) I cant test it for you, if you send all the code I can test this out and get it working for you. Quote Link to comment https://forums.phpfreaks.com/topic/222926-watermark-script/#findComment-1152845 Share on other sites More sharing options...
sdi-graphics Posted December 30, 2010 Author Share Posted December 30, 2010 Tank YOU for your reply Sorry I'm not getting it this is all the code I'm using. The watermark_wrapper.php and the .htaccess and the watermark.png It took a long time to get something to work on my site. The only problem I have is the uploaded image size varies. On some images the watermark is to big and on others to small. If my two part script could re-size the watermark image according to the size of the display image. This code needed would have to go in to the wrapper.php The only part missing in my first post is the watermark.png image and the size is 250x250pix [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/222926-watermark-script/#findComment-1152871 Share on other sites More sharing options...
sdi-graphics Posted December 30, 2010 Author Share Posted December 30, 2010 I should mention Thad I need all images uploaded in to this directory watermarked. This is why I went this route Quote Link to comment https://forums.phpfreaks.com/topic/222926-watermark-script/#findComment-1152874 Share on other sites More sharing options...
hackalive Posted December 31, 2010 Share Posted December 31, 2010 Alot of work to go, but here is my progress so far: <?php // path to image $path = $_SERVER['DOCUMENT_ROOT'].'/watermark/picture.jpg'; // upload the image $image = imagecreatefromstring(file_get_contents($path)); // get image dimensions $w = imagesx($image); $h = imagesy($image); // set percentage watermark shoudl cover. (NB: 30.00 = 30%) $p = 30.00; // do percentage calculations $wp = ($p/100)*$w; $hp = ($p/100)*$h; // get watermark $watermark = imagecreatefrompng('watermark2.png'); // get watermark dimensions (NB: NOT USED ANYMORE, KEPT FOR YOUR REFERENCE) $ww = imagesx($watermark); $wh = imagesy($watermark); // rescale image $source_image = imagecreatefrompng("watermark.png"); $source_imagex = imagesx($source_image); $source_imagey = imagesy($source_image); $dest_imagex = $wp; $dest_imagey = $wh; $dest_image = imagecreatetruecolor($dest_imagex, $dest_imagey); imagecopyresampled($dest_image, $source_image, 0, 0, 0, 0, $dest_imagex, $dest_imagey, $source_imagex, $source_imagey); // place watermark imagecopy($image, $dest_image, (($w-$wp)/2), (($h-$hp)/2), 0, 0, $wp, $hp); // display new image header('Content-type: image/jpeg'); imagejpeg($image); imagedestroy(); exit(); ?> Ill see if I cant fix the bugs later and get them to you in the first day or two of the new year. Quote Link to comment https://forums.phpfreaks.com/topic/222926-watermark-script/#findComment-1153244 Share on other sites More sharing options...
sdi-graphics Posted January 8, 2011 Author Share Posted January 8, 2011 Thank You so match for your help I try this as soon I get home I'm gone till 10 January. Sorry I reply so late but I hat to fined a pc first Quote Link to comment https://forums.phpfreaks.com/topic/222926-watermark-script/#findComment-1156585 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.