There is no "trick". You cannot "prevent users from getting images".
Every server-side resource, that means images, HTML pages, stylesheets, everything, needs to have a URL by which they can be downloaded. The browser makes a request to download a URL, receives the response to that request, and then treats it accordingly as an HTML page, image, or whatever else.
You cannot have one URL return two different things. I mean, you can, your server could randomly return different content each time the URL is being accessed. But that's pretty nonsensical. If you want your visitors to see your image, you will need to give them one unique URL where they can do so. If you don't want your visitors to see your image, don't put it online.
If you do let your visitors see your image, that means they need to download it to their computer. They need a URL for that. Your visitors don't care at all whether that URL ends in .php
or .jpg
. All they know is that a request to that URL will return that image. Your "trick" doesn't do anything. You still end up with a URL from which an image can be downloaded.
Once the image is downloaded and the visitor can see it, it's on their computer. You can't prevent user's from getting the image yet also see the image. What you want is nonsense.
(This answer may seem somewhat rambling, but addresses the original revision of the question.)