You can create .htaccess file and then add below code in that file:
Where domain.com is your domain.
Code:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https://(www.)?domain.com.*$ [NC]
RewriteRule .(gif|jpg)$ – [F]