How to create a script that automatically detects images?