Checking the File Integrity of a Series of Images
August 3, 2017Recently, I blogged about my Family Dashboard I had created.
This project contains (among others) a module that synchronizes a specific Google Photos album with a local server. The code performing this synchronization had (maybe still has) some issues and I occasionally ended up with corrupted (partially downloaded) images.
Picking these corrupted images out by hand wasn't an option so I asked Google:
Is there a tool to check the file integrity of a series of images?
You bet there is ... Google answered ... and pointed me to jpeginfo.
Installation
You can either clone the repo and compile it yourself ...
$ git clone https://github.com/tjko/jpeginfo.git
... or just install it, which is what I did.
apt-get install jpeginfo
Run the check
I does exactly the job I needed it for. Navigate into the directory where the potentially corrupted images are stored and run the tool with the -c (check) option.
$ jpeginfo -c *
...
BE9CBCA5-40DB-4807-8C04-D40C531BD59C.JPG 960 x 1280 24bit Exif N 161282 [OK]
BE9F09B2-DFD0-4A83-8953-A4FF1C86FC9D.JPG 960 x 1280 24bit Exif N 233407 [OK]
C4FB6F90-10C7-456C-8448-7D592D3D810E.JPG 960 x 1280 24bit Exif N 583064 [OK]
C50E8437-5F8B-44EA-B803-976C26186779.JPG 960 x 1280 24bit Exif N 232892 [OK]
C6A6DAFB-5B21-48C8-BF7E-E3BD83868AFA.JPG 1280 x 719 24bit Exif N 197044 [OK]
C78910F8-A1CE-455C-99CF-AD0D618BDA0C.JPG 960 x 1280 24bit Exif N 383026 [OK]
CA177593-1366-4132-B5FB-C82AAAEC256D.JPG 1280 x 1280 24bit Exif N 633077 Premature end of JPEG file [WARNING]
CB05749A-023C-4AEE-9178-0F0552385067.JPG 960 x 1280 24bit Exif N 161007 [OK]
CDCD0292-854B-49A8-8E6E-79DC3BEC7B63.JPG 1280 x 960 24bit Exif N 234577 [OK]
D0407323-A757-400B-B14F-47C840D694D7.JPG 960 x 1280 24bit Exif N 215139 [OK]
...
A couple of [WARNING] entries appear. These are the corrupted files.
Automatically delete
So let's get rid of them (and assume that synchronization will work next time).
Run the tool again with the "delete all" option (-d -mall).
$ jpeginfo -c -d -mall *
All done. Next time I need this, I can just look up my own blog post.