I often have this sitation, and need to use the part excluding the ā_1.jpgā etc. as a foreign key - as you do, if I understand correctly.
I add an extra, virtual/generated column in the table, which extracts the part before the delimiter (ie ignores the _1.jpg etc in your example). This is an example expression:
if(locate('-',
img_filename),substr(
img_filename,1,(locate('-',
img_filename) - 1)),substr(
img_filename,1,(locate('.',
img_filename) - 1)))
(The delimiter in this case is a hyphen)
So the two columns will be:
If you are using MySQL, you will need to be using 5.7 (otherwise you could use a trigger). I donāt know about other databases.
I imagine this method wonāt be required when we can create custom queries. However, there might be advantages in this approach in any case.