Photo Corners headlinesarchivemikepasini.com


A   S C R A P B O O K   O F   S O L U T I O N S   F O R   T H E   P H O T O G R A P H E R

Enhancing the enjoyment of taking pictures with news that matters, features that entertain and images that delight. Published frequently.

Ingester Gets Some AI Help Share This on LinkedIn   Tweet This   Forward This

6 February 2024

Since we last looked at Ingester, our Keyboard Maestro macro to import images from a variety of sources to our archive, we've been enjoying the streamlined efficiency of the latest version. Actual, pure, unfiltered enjoyment, yes.

Yet Another Refinement. Here's the code we developed with some AI assistance.

But the other day, we accidentally shot some JPEGs on a camera which we normally record only Raw files. And Ingester identified them as phone images.

We thought we could improve that in case we really do want to shoot JPEGs with a camera (which we haven't done for years but, after all, some old cameras only shoot JPEG).

IDENTIFYING THE SOURCE

There are two ways we can identify whether the images were taken by a camera or a phone. They are different archives for us, which is why we want to know.

The first is the source. Is it an AirDrop transmission? Phone. Is it from an SD card? Camera.

While Ingester uses that information to branch into code specific for each, like waiting for AirDrop to finish or ejecting a card, it doesn't determine the image source from it. That's because a phone connected by cable can be mistaken for a camera.

So, instead, it looks at the file extensions of the copied image files.

On our system we know that certain file name extensions indicate specific sources. For example:

  • HEIC: Phone
  • DNG: Phone
  • nef, cr2, orf: Camera

But JPG can be either. As it happens, only our iPhone 6 Plus saves JPEGs as ".JPG" but our cameras do too. We just don't use that format.

EXIFTOOL TO THE RESCUE

To resolve this conflict, all we have to do is check the Maker Exif tag in one JPEG file. And to do that, all we have to do is run Phil Harvey's ExifTool. Harvey recently retired from his day job but, fortunately, still maintains ExifTool.

We run a batch script within Keyboard Maestro that does several things. Here's the logic:

  • Count any JPG or HEIC or DNG files (note the uppercase extensions) as $Ph
  • Count the JPG files as $Jp
  • Count the nef/cr2/org files as $Cm
  • If there are any JPG files, report the Maker of the first one
  • If that's not Apple or iPhone, subtract $Cm from $Ph
  • But if it is, subtract $Ph from $Cm
  • But if there aren't any JPG files, subtract $Ph from $Cm
  • Send that number back to Keyboard Maestro

AI TO THE RESCUE

We don't write much bash code so the syntax wasn't natural to us. To get some help, we tried searching online but between the advertising and only barely relevant results, the experience was more frustrating that usual.

Instead we launched WaveLength, a group chat app that lets you post a query to its AI engine which, in a heart beat or two, returns a suggestion.

It isn't cut-and-paste code but it does suggest an approach and the syntax is correct. Which was all we needed.

Here's the current code:

Ph=$(find ~/Pictures/\ temp/ -name "*.JPG" -o -iname "*.HEIC" -o -name "*.DNG"
		-maxdepth 1 | wc -l)
Jp=$(find ~/Pictures/\ temp/ -name "*.JPG" -maxdepth 1 | wc -l)
Cm=$(find ~/Pictures/\ temp/ -iname "*.nef" -o -iname "*.cr2" -o -iname "*.orf"
		-maxdepth 1 | wc -l)
if [ $Jp -gt 0 ]; then
	$dir = "~/Pictures/ temp"
	jpeg_file=$(ls $dir/*.JPG 2>/dev/null | head -n 1)
	make=$(exiftool -Make -s3 $jpeg_file)
	if [[ $make != *"Apple"* && $make != *"iPhone"* ]]; then
		echo $(($Cm - $Ph))
	else
		echo $($Ph - $Cm)
	fi
else
	echo $(($Ph - $Cm))
fi

THE NUMBER PLEASE

It may not be obvious but what this returns is either a positive or negative number. A positive number indicates we have phone images and a negative number indicates they are camera images.

We want to know the number of images we are processing to display in our control panel.

But we don't want it to display a negative number so we convert that with Keyboard Maestro's ABS or absolute number function.

OR ELSE

We could simply have moved our test for JPG files to the line that tests for camera images but that would have incorrectly identified iPhone 6 Plus images. And that phone is still laying around here, which means we could pick it up at any moment and complicate our lives.

This approach more accurately identifies the source of the images we take.

But you can see it's tailored to what our cameras do. A more general approach might ignore the file extensions entirely and read the Maker tags instead. That wouldn't work any better for our situation, though.

So we're sticking with this enjoyable (and even more reliable) approach.


BackBack to Photo Corners