Is there a hook to override access to images stored in the private file system when theme_image_style is used to output the image?

2 Answers 2


Image styles are served from the public file system, and there's no hook to control access to public files, so unfortunately not.

There's no simple solution, but there is a working solution: Image Style Access

Allows granular access control to images and image style derivatives.

I've had a quick look through the code and you won't find a better starting point than that module. Quite a straightforward idea actually, it introduces a menu router item for each ./styles/[image-style] folder, controlled by an access callback.

It does mean you now have the overhead of a full bootstrap for all image styles, but since you want to check access based on the DB there's no other way to do it.


@Clive Thanks for the suggestion, in the end I did find an answer to this and it was quite easy.

hook_file_download($uri) https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_file_download/7

For what I needed this worked just great. It is called everytime a private file is accessed through the drupal system.

I can easily do the checks on the user logged in when this hook is called and just return 1 if the user should be allowed access to the file or -1 if I want to deny access.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.