protect images from being copied

Vincent Duprez

Im looking for reliable solutions to protect images from being copied.. My customer (photographer) would like to avoid customers copying her pictures without buying them.

I was thinking about mixing these techniques:


PHP self-made expiration

images are loaded from a php script reading from the image file, in the request I bundle the request timestamp and filename. if the timestamp is very close to the actual timestamp (both timestamps are generated on the same server, so no time config issues) the request is created on page generation. For example: in the generated html, I have some img tag like:

So when the users wants to copy the image source from source code, the image.php script won't answer as there is a delay between page generation and image request...

No caching

If I send a No cache header, I suppose the browser doesn't caches/stores the file on the client computer?


Now that's the basic idea.. Users don't have the original file name so can't acces them directly.. With this solution, I can even watermark them on the fly or resize them

Users could still print screen them, there are 2 types of printscreens, those that put them in the clipboard, and those that save a file.

Would there be a solution, I was thinking about some sort of javascript side onkeydown and detecting the printscreen touch, or shift+alt+cmd+[1-4] on mac cobination and blank out imagesbefore any action is taken.. is this possible, more or less reliable and how?

Another partial idea I had was to clear clipboard on an interval or some action, but this is annoyinng for people, doesn't work for desktop saved screen captures and maybe doesn't works on all browsers.

any other idea?

So where to go from here? This is a practical question, I know people could take a picture of their screen after all or use a hdmi cable to capturing device.. but seriously, this is overkill, no one will do this for such pictures, we're not talking about top secret classified documents...

Vincent Duprez

So this is my implementation:

First when calling an image during a page generation in php:

$reqinfo['id'] = $data[id];
$reqinfo['maxsize'] = 320;
$reqinfo['timestamp'] = time();
$reqinfo['base'] = false;

$encoded = base64_encode(openssl_encrypt(serialize($reqinfo), 'AES-128-CBC', 'martine',0,'fgrgfvcfghtfdrfg'));

echo'<div class="imagecontainer"><img src="photo.php?info='.$encoded.'" /></div>'; 

This already implement some restrictions in css and javascript on the imagecontainer class. I send the image ID (or name) the maximum width or height and the request timestamp, all this encrypted in a request string sent to photo.php base is ment to be true if image may bypass everything and be called like a plain image.

photo.php

<?
//request info
$reqinfo = unserialize(openssl_decrypt(base64_decode($_GET[info]), 'AES-128-CBC', 'martine',0,'fgrgfvcfghtfdrfg'));

//image expired
if(time() - $reqinfo[timestamp] > 10){ exit(); }

//public image
if($reqinfo[base] == true){ readfile('img/'.$reqinfo[id].'.jpg'); exit(); }

//header cache
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header('Content-type: image/jpeg');

//check cache existance and send out
if(file_exists( 'img/'.$reqinfo[id].'_'.$reqinfo[maxsize].'.jpg')) { readfile('img/'.$reqinfo[id].'_'.$reqinfo[maxsize].'.jpg'); exit(); }

//source Image
$image_path = 'img/'.$reqinfo[id].'.jpg';
list($original_width, $original_height)= getimagesize($image_path); 
$srcImage = imagecreatefromjpeg( $image_path );
$ratio = $original_height/$original_width;


//create destination image holder
$destination_width = $reqinfo['maxsize'];
if($destination_width < 1) $destination_width = 1;
if($destination_width > $original_width)$destination_width = $original_width;
$destination_height = round($destination_width*$ratio);
if ($destination_height > $reqinfo['maxsize'])
{
    $destination_height = $reqinfo['maxsize'];
    $destination_width = round($destination_height/$ratio);
}
$targetImage = imagecreatetruecolor( $destination_width, $destination_height );
imagealphablending($targetImage,true);

//resample copy logo
imagecopyresampled( $targetImage, $srcImage, 
0, 0, 
0, 0, 
$destination_width, $destination_height, 
$original_width, $original_height );


// watermark
$watermark = imagecreatefrompng('watermark.png');
imagesettile($targetImage, $watermark);
imagefilledrectangle($targetImage, 0, 0, $destination_width, $destination_height, IMG_COLOR_TILED);




//output
imagejpeg(  $targetImage, 'img/'.$reqinfo[id].'_'.$reqinfo[maxsize].'.jpg' );
imagejpeg(  $targetImage );
imagedestroy( $targetImage );


?>

'martine' is a simple passphrase img is obviously an non public path

Hope this is more or less clear, basically this (in order):

  • Decrypt the $reqinfo array
  • check if imagerequest is fresh, if a user copies the urls and loads in another frame, no image will be loaded.
  • Checks if the image can bypass resize and watermark and be sent to the browser
  • Checks if a cached version exists to speed up process
  • Recreates a resized version
  • Add a watermark
  • Saves a server cached version
  • sends out the 'disposable' image

Hope this can helps someone...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to Protect Windows OS Image From Being Copied?

From Dev

Protect Images from being public laravel 5

From Dev

Avoid the li tag symbol from being copied

From Dev

Protecting raw JSON data from being copied

From Dev

Prevent line numbers from being copied to clipboard

From Dev

SQL Server DB stop from being copied

From Dev

Is there a way to (actually) protect an object from being modified?

From Dev

How to protect columns in hibernate from being read

From Dev

Will this approach protect my database from being modified?

From Dev

How to protect bash function from being overridden?

From Dev

Is there a way to protect a file from being deleted, but not from being altered?

From Dev

How to protect images.xcassets from stealing?

From Dev

Prevent session from being replicated when JSESSIONID cookie copied

From Dev

cp command to exclude certain files from being copied

From Dev

Can I prevent object from being copied by std::memcpy?

From Dev

How to exclude some fields from being copied to realm database?

From Dev

cp command to exclude certain files from being copied

From Dev

Protecting Virtual machine from being copied to other hosts

From Dev

How to exclude some files from being copied using xcopy?

From Dev

Is there a very effective method to prevent a .jpg file for being copied from a page?

From Dev

How to exclude some fields from being copied to realm database?

From Dev

gulp src - exclude folders from being copied on task execution

From Dev

How can I protect a matrix in R from being altered by Rcpp?

From Dev

How to protect my Javascript from being accessed by other parties?

From Dev

Protect PDF docs from being directly accessed in URL

From Dev

Is there a way to protect a class variable from being modified outside of a function

From Dev

How can I protect sqlite db in android from being stolen

From Dev

How to protect my Javascript from being accessed by other parties?

From Dev

Will sandboxing a program protect my computer from being damaged?

Related Related

  1. 1

    How to Protect Windows OS Image From Being Copied?

  2. 2

    Protect Images from being public laravel 5

  3. 3

    Avoid the li tag symbol from being copied

  4. 4

    Protecting raw JSON data from being copied

  5. 5

    Prevent line numbers from being copied to clipboard

  6. 6

    SQL Server DB stop from being copied

  7. 7

    Is there a way to (actually) protect an object from being modified?

  8. 8

    How to protect columns in hibernate from being read

  9. 9

    Will this approach protect my database from being modified?

  10. 10

    How to protect bash function from being overridden?

  11. 11

    Is there a way to protect a file from being deleted, but not from being altered?

  12. 12

    How to protect images.xcassets from stealing?

  13. 13

    Prevent session from being replicated when JSESSIONID cookie copied

  14. 14

    cp command to exclude certain files from being copied

  15. 15

    Can I prevent object from being copied by std::memcpy?

  16. 16

    How to exclude some fields from being copied to realm database?

  17. 17

    cp command to exclude certain files from being copied

  18. 18

    Protecting Virtual machine from being copied to other hosts

  19. 19

    How to exclude some files from being copied using xcopy?

  20. 20

    Is there a very effective method to prevent a .jpg file for being copied from a page?

  21. 21

    How to exclude some fields from being copied to realm database?

  22. 22

    gulp src - exclude folders from being copied on task execution

  23. 23

    How can I protect a matrix in R from being altered by Rcpp?

  24. 24

    How to protect my Javascript from being accessed by other parties?

  25. 25

    Protect PDF docs from being directly accessed in URL

  26. 26

    Is there a way to protect a class variable from being modified outside of a function

  27. 27

    How can I protect sqlite db in android from being stolen

  28. 28

    How to protect my Javascript from being accessed by other parties?

  29. 29

    Will sandboxing a program protect my computer from being damaged?

HotTag

Archive