Hide user pictures from guests and web crawlers I'm using Drupal 7 with Blog and Comments and user pictures enabled. The theme is Bartik.

The user pictures are also used in the Flash game that is embedded in my website, so I can't just turn them off.

I'm looking for a way to hide user avatars from guests and web crawlers.

The background is that I've gotten a bill for EUR 1000,- from Getty Images, because one of the users has supposedly used their picture as avatar. I'm not looking for any lawyer or pseudo-lawyer advices here, just for the way to hide user pictures from web crawlers.

I've tried searching in the theme file for picture and bartik_preprocess, but haven't find any hints yet:

# grep -r bartik_preprocess .
./themes/bartik/template.php:function bartik_preprocess_html(&amp;$variables) {
./themes/bartik/template.php:function bartik_preprocess_maintenance_page(&amp;$variables) {
./themes/bartik/template.php:function bartik_preprocess_node(&amp;$variables) {
./themes/bartik/template.php:function bartik_preprocess_block(&amp;$variables) {


and print_r($variables); in the above functions does not contain a "picture".

Also I've tried setting $account->picture = NULL; in the hook_user_view($account, $view_mode, $langcode) hook, but then the picture is hidden for everyone including registered users and also this is for user profiles only, not for blog comments.
None of the core themes have all the preprocess functions or template file in use. The best way to find what's available to use is with the devel_themer module.

Here's what devel_themer gave me:



This says we can use template_preprocess_user_image() or user-picture.tpl.php. When doing logic such as this, it's standard to use preprocess functions. When you're changing HTML structure you use template files.

So you can add the following function to your theme and it should hide all user pictures for anonymous users (web scrapers are considered anonymous users).

function YOURTHEME_preprocess_user_picture(&amp;$variables) {
  // this is the currently logged in user
  $user = $variables['user'];

  // this is the user the picture belongs to
  $account = $variables['account'];

  // If the current user is anonymous don't show the user picture
  if ($user-&gt;uid == 0) {
    $variables['user_picture'] = NULL;
  }
}