Jump to content

Detecting if you are watching a picture or a picture in a <img /> code


Third

Recommended Posts

Hi!

Im using a php-file to put out a jpg header. It gathers the data from an image gallery database via mysql.

 

The problem is, I want it to load two different versions of it.

 

One version is what you see when i call the <img src='photo.php&id=50' />, the picture in the img tag on one page,

and the other version is if you clicked my direct link to the picture.

 

Is there some way i can find out if the photo.php is a part of another web-page, like if it it was included on gallery.php

and if photo.php is viewing only the jpg?

 

the photo.php is getting data from my database and results in something like:

 

header('Content-type: image/png');

$im = imagecreatefromjpeg($imglink);

imagejpeg($im);

imagedestroy($im);

 

I've tried to make some workarounds, like in gallery.php to set a variable and

trying to read it in photo.php, (wich would not be made if you just visited photo.php)

but it didnt work out. I just get the same results in both.

 

I want to show the pic in a img tag without any watermarks, and if the user goes to the photo via photo.php,

it adds the watermark..

 

I hope you understand my question and how I do this :)

 

I'm not a hundred percent clear exactly what your after but...

 

At the point of image generation / inclusion, you should know which image it should be!

So, you generate the image accordingly, either by calling another script or using GET / POST:

header('Content-type: image/png');
if(isset($_GET['mark'])){$im = imagecreatefromjpeg($imglink);}
else{$im = gen_image();}
imagejpeg($im);
imagedestroy($im);

 

To decide depending on where it came from you can use $_SERVER['HTTP_REFERER'], but it might not always be set.

 

For protection you could do similar to when doing CAPTCHA's, generate a ref in the db, the image page reads the ref to see if still valid, etc...

 

 

I hope something helped because still unsure... lol

Try to see it like this. I want a script that can detect if you are either:

 

1. Seeing the picture in a webpage, by using <img src='thatimage' />

 

and

 

2. If you right click that image in the webpage, and chose View Image, it opens only the image and I want to detect this from 1.

 

So basically, when im showing the picture using <img>, i want it to show without watermark. If user clicks the image to see it in full screen in the browser, i want watermark on it.

 

What I have done now is that im showing the image using the direct link for the image in the <img>.. like src='/bla/folder/file.jpg'

and i have that <img> in a href link to a php script that generates that picture, with a water mark.

 

You can see here: http://nesthus.net/photo/263

 

if i include that php script on that page, in the <img src=', i will have watermarks on the picture there wich is unwanted.

 

Thanks for trying!

why dont you add a parameter in the image src.. like

 

<img src='filename/id/fromimagesource' />

 

and when you get it on the file.. check for that parameter.. if it is there do not add watermark.. if it is not.. then only add watermark

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.