RewriteEngine on

RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost [NC]

RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost.*$ [NC]

RewriteRule \.(gif|jpg)$ – [F]