How do I write a Perl script to filter out digital pictures that have been doctored?


Last night before going to bed, I browsed through the Scalar Data section of Learning Perl again and came across the following sentence:

the ability to have any character in a string means you can create, scan, and manipulate raw binary data as strings.

An idea immediately hit me that I could actually let Perl scan the pictures that I have stored on my hard disk to check if they contain the string Adobe. It seems by doing so, I can tell which of them have been photoshopped. So I tried to implement the idea and came up with the following code:

use autodie;
use strict;
use warnings;

    local $/="\n\n";
    my $dir = 'f:/TestPix/';
    my @pix = glob "$dir/*";

    foreach my $file (@pix) {
        open  my $pic,'<',  "$file";

        while(<$pic>) {
            if (/Adobe/) {
                print "$file\n";

Excitingly, the code seems to be really working and it does the job of filtering out the pictures that have been photoshopped. But problem is many pictures are edited by other utilities. I think I’m kind of stuck there. Do we have some simple but universal method to tell if a digital picture has been edited or not, something like

if (!= /the origianl format/) {...}

Or do we simply have to add more conditions? like

if (/Adobe/|/ACDSee/|/some other picture editors/)

Any ideas on this? Or am I oversimplifying due to my miserably limited programming knowledge?

Thanks, as always, for any guidance.


Your best bet in Perl is probably ExifTool. This gives you access to whatever non-image information is embedded into the image. However, as other people said, it’s possible to strip this information out, of course.

Answered By – user181548

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published