Watermark hotlinked image

Started by dschwab9, October 28, 2003, 04:05:57 AM

Previous topic - Next topic

dschwab9

Quote from: [Unknown] on October 29, 2003, 05:07:23 PM
I always prefer something like this over switches:

$extension = strtolower(strrchar($image, '.'));
if ($extension == 'jpg')
   $extension = 'imagecreatefromjpeg';
elseif (!function_exists('imagecreatefrom' . $extension))
   $extension = 'imagecreatefrompng';
else
   $extension = 'imagecreatefrom' . $extension;

$photoImage = $extension('/' . $image);

-[Unknown]

Is that case insensitive?  Would it treat JPG, jpg, and JpG equally?
One of the things I'm using this with is a photo hosting service I run in conjunction with my forum, and you never know what the user will upload as far as case goes.

I was originally using ImageMagick to watermark the images before they were stored on the disk.  What I'm doing now is storing them in their original format, allowing them to be posted on my forum with no watermark, but watermark them if they are posted elsewhere.

[Unknown]

PHP internal functions are, yes, case insensitive.  That's why "Header" "header" and "HEADER" all work, although I prefer using all lowercase. (because that is what the actual name is.)

-[Unknown]

Aquilo

Quote from: [Unknown] on October 29, 2003, 09:59:36 PM
It's much easier on windows.  It's called "dl('php_gd.dll');".

-[Unknown]

I was reading the FAG at GD befor I went to bed and it said the folks at PHP had an up-to-date / custom version but it's only in the php 4.3.x .zip file not the .exe so I'm hoping I can just copy the files to the curent php install, but it's downloading now! ;D

Aquilo

well getting GD to work on IIS is a small token of happiness lately, oh well I'll keep the source files maybe I learn to compile them! :D

Shoeb Omar

Quote from: Aquilo on October 30, 2003, 04:19:20 AM
Quote from: [Unknown] on October 29, 2003, 09:59:36 PM
It's much easier on windows.  It's called "dl('php_gd.dll');".

-[Unknown]

I was reading the FAG at GD befor I went to bed and it said the folks at PHP had an up-to-date / custom version but it's only in the php 4.3.x .zip file not the .exe so I'm hoping I can just copy the files to the curent php install, but it's downloading now! ;D

sorry, but am I the only one who thought that "reading the FAG" sounded weird? ;)

Jack.R.Abbit™

Quote from: Shoeb Omar on October 30, 2003, 07:56:03 AM
Quote from: Aquilo on October 30, 2003, 04:19:20 AM
Quote from: [Unknown] on October 29, 2003, 09:59:36 PM
It's much easier on windows.  It's called "dl('php_gd.dll');".

-[Unknown]

I was reading the FAG at GD befor I went to bed and it said the folks at PHP had an up-to-date / custom version but it's only in the php 4.3.x .zip file not the .exe so I'm hoping I can just copy the files to the curent php install, but it's downloading now! ;D

sorry, but am I the only one who thought that "reading the FAG" sounded weird? ;)
Frequently Accepted Guesses? :D

Aquilo

sorry F.A.Q. ;D

but like I said getting both the installer and zip distribution worked out great because the zip had all the libraries bundled with it and the installer kept me lazy! :D 8)

but I did have to edit php.ini by hand. ;D

Anguz

Cristián Lávaque http://cristianlavaque.com

asstreet

Hello, Would you please tell me how i am going to create this thing? I mean would you please tell me step by step direction for creating this script? Thank you


Quote from: Aquilo on October 28, 2003, 07:57:15 AM
you could pass the image they are hot linking with your logo like this

RewriteEngine on
RewriteCond %{HTTP_REFERER}   !^http://www\.yoursite\.com/$   [NC]
RewriteRule ^(.*)\.(gif|jpg|png)$ image_script.php?image=$1\.$2   [R]


that should work I can't test it at this time.

and the GD script could be name: image_script.php
<?php
switch (TRUE) {
   case stristr($image,'jpg') :
      $photoImage = ImageCreateFromJPG("/$image");
      break;
   case stristr($image,'gif') :
      $photoImage = ImageCreateFromGIF("/$image");
      break;
   case stristr($image,'png') :
      $photoImage = ImageCreateFromPNG("/$image");
      break;
}

ImageAlphaBlending($photoImage, true);

// if your logo is not a png use top examples to change it's format in create from line
$logoImage = ImageCreateFromPNG("/your_logo.png");
   $logoW = ImageSX($logoImage);
   $logoH = ImageSY($logoImage);

// were you see the two 1's this is the offset from the top-left hand corner!
ImageCopy($photoImage, $logoImage, 1, 1, 0, 0, $logoW, $logoH);

ImagePNG($photoImage); // output to browser

ImageDestroy($photoImage);
ImageDestroy($logoImage);
?>

[edit] I guess the <?php thing is broke! [/edit]

anyway this should work again I can't test it!

Elijah Bliss

This is a great script, but would it work on a folder of images? People like to hotlink my smilies.

Ben_S

Think I'll implement it too. On the subject of hotlinking, I've got a 10MB vid file thats going round the web and have been pushing ~30GB a day for the past 3 days.
Liverpool FC Forum with 14 million+ posts.

Advertisement: