0

Think stock images. You have a full-size original that can only be downloaded after purchase. You only want to have that image once on your server, at full-size. But you want to display that image in various places in smaller sizes (responsively reduced for mobile devices as well).

I've got various pieces of this puzzle, but have not been able to make them all work together:

With TimThumb or CImage I can resize the images server-side, and using jQuery I can dynamically change the image source based on the user's screen size.

With PHP and .htaccess I can place the image files outside of the webroot and route a spoof URL containing image name to the PHP file that will read the actual image and send a header with the image data. Fine.

But TimThumb and CImage work with the real image URLs and they test to make sure that the given URL is the actual file path of the image.

If I could send the actual image data to the image resizing script rather than the URL to the image, it should work out from there. Since the PHP script would be reading the image data, I could check to see that the user has been given the proper credentials before doing the read.

Are there any other solutions you can think of besides hacking TimThumb or CImage or writing my own custom image resizing script?

Thank you

i_a
  • 2,735
  • 1
  • 22
  • 21
  • Is your image resizing logic so complex that creating some small image scaling script is really too much work? I'll have to admit that it's been a while I developed image processing stuff in PHP, but I remember that using [ImageMagick](http://php.net/manual/book.imagick.php) made everything very easy. – Hauke P. Jul 20 '14 at 18:46
  • I like the features of TimThumb and CImage, especially CImage; allows many cropping options. So yeah, instead of re-inventing the wheel, or modifying wheels in existence, it would be great to make them work by some server config trick. Thanks for asking. – i_a Jul 20 '14 at 18:57

1 Answers1

0

The answer just came to me.

With .htaccess, route all images through the image processing script. On the first line of the image processing script I will include my own custom script. My custom script will check the GET parameters against the actual image to determine if the user has the credentials to be served the image being requested at the size it is being requested.

If so, let the image processing script continue, if not, exit out or change the GET parameters to that the image processing script serves a placeholder image.

Voilà!

i_a
  • 2,735
  • 1
  • 22
  • 21