Jump to content

watermark script


sdi-graphics

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.