ExifTool Forum

ExifTool => The Image::ExifTool API => Topic started by: StarGeek on August 05, 2024, 09:34:06 PM

Title: qrencode config file
Post by: StarGeek on August 05, 2024, 09:34:06 PM
Based upon Alan Clifford's idea (https://exiftool.org/forum/index.php?msg=87655) to create QR codes from an image's GPS coordinate, I put together this config file that will create a QR PNG image if a file has a GPSLatitude/GPSLongitude.

It can be run with a command such as this
exiftool -config GPSQRCode.config -GPSQRCode -b -W %d%f-QR.png /path/to/files/

#------------------------------------------------------------------------------
# File:         GPSQRCode.config
#
# Description:  User-defined Composite tag to create a GPS QR code
#                   by running qrencode
#
# Tag definition and example:
#
#   GPSQRCode
#       This will create a QR code image for any file that has GPS coordinates.
#
#       Example:
#           exiftool -config GPSQRCode.config -GPSQRCode -b -W %d%f-QR.png /path/to/files/
#
#
# Revisions:    Ver. 1.0 - 2024-08-05 - Bryan K. Williams (aka StarGeek) Created
#                    1.1 - 2024-08-06 - Fixed output so the returned image shows up tagged as Binary (thanks Phil)
#
# References:
#               https://github.com/fukuchi/libqrencode
#               Windows Port
#               https://sourceforge.net/projects/qrencode-for-windows/
#               Tutorial
#               https://www.howtogeek.com/devops/how-to-create-qr-codes-from-the-linux-command-line/


%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {

        GPSQRCode => {
            Require => {
                0 => 'GPSLatitude',
                1 => 'GPSLongitude',
            },
            Binary => 1,
            ValueConv => q{
                # Hide STDERR so it doesn't display on command line
                use File::Spec;
                open STDERR, '>', File::Spec->devnull() or warn "Warning: could not hide STDERR";

                # Set GPS tags in new image
                my $et = new Image::ExifTool;
                $et->SetNewValue('EXIF:GPSLatitude',$val[0]);
                $et->SetNewValue('EXIF:GPSLongitude',$val[1]);

                # run qrencode
                my $QRCode = `qrencode -s 6 -l H -o - "geo:$val[0],$val[1]"`;
                warn "Error running qrencode" and return undef unless $QRCode;
                my $success = $et->WriteInfo($QRCode);
                return \$QRCode;
            },
        },
    },
);
#------------------------------------------------------------------------------
1;  #end

The "Hide STDERR" stuff is in there because I was going to check to make sure qrencode existed first by running
qrencode --version
but the problem with that is that the version info was output to STDERR.  Also, this would mean running qrencode twice for every image. So that might get dropped if there's an update.

The current problem is that exiftool doesn't recognize the data as Binary, so it will display the contents of the PNG file directly on the command line if the -W (-TagOut) option (https://exiftool.org/exiftool_pod.html#W-FMT--tagOut) isn't used. Fixed

I'm probably using the Binary => 1, flag incorrectly or in the wrong spot. Phil, what would be the correct way to get the tag marked as binary? Fixed

If there's any interest, it would be possible to add some -UserParams (https://exiftool.org/exiftool_pod.html#userParam-PARAM-VAL) to change some of the command line options, such as making it larger or changing the colors of the output file.

The How To Geek page (https://www.howtogeek.com/devops/how-to-create-qr-codes-from-the-linux-command-line/#installing-qrencode) listed in the file has instructions on installing on the qrencode program on Linux. There is also a Windows port (https://sourceforge.net/projects/qrencode-for-windows/) of the program.
Title: Re: qrencode config file
Post by: Phil Harvey on August 06, 2024, 07:07:20 AM
It looks like the Binary flag doesn't work for Composite tags.  But you can do the same thing by returning \$QRCode (a reference to $QRCode) instead of $QRCode directly.

- Phil

Edit:  Ah.  From lib/Image/ExifTool/README:

                  Binary' - set to 1 for binary data.  This has the same effect
                  as setting ValueConv to '\$val', but it it a bit cleaner and
                  avoids dummy ValueConvInv entries for writable tags.  Has no
                  effect if ValueConv is defined for the tag.
Title: Re: qrencode config file
Post by: Alan Clifford on August 06, 2024, 08:06:01 AM
@StarGeek I'm a little confused.  In my photos, exif:gpslatitude doesn't have a north or south of the equator

[EXIF]          GPS Latitude Ref                : South
[EXIF]          GPS Latitude                    : 33 deg 13' 54.68"
[XMP]           GPS Latitude                    : 33 deg 13' 54.68" S
[Composite]     GPS Latitude                    : 33 deg 13' 54.68" S
[Composite]     GPS Latitude Ref                : South

Title: Re: qrencode config file
Post by: StarGeek on August 06, 2024, 09:44:31 AM
Quote from: Alan Clifford on August 06, 2024, 08:06:01 AMIn my photos, exif:gpslatitude doesn't have a north or south of the equator

The EXIF GPS tags (called GPS tags (https://exiftool.org/TagNames/GPS.html) by exiftool) are split into two separate tags. The GPSLatitude/GPSLongitude/GPSAltitude tags hold the actual coordinate values and the GPSLatitudeRef/GPSLongitudeRef/GPSAltitudeRef tags hold the directional values (N/S, E/W, Above/Below).

It shouldn't be a problem with this config file, as it doesn't use a specific location, so it should default to the Composite GPS tags. Those tags should include the reference direction if it is in the file somewhere.
Title: Re: qrencode config file
Post by: StarGeek on August 06, 2024, 09:46:10 AM
Quote from: Phil Harvey on August 06, 2024, 07:07:20 AMEdit:  Ah.  From lib/Image/ExifTool/README:

Somehow I always overlook that file. I have to do something to make sure that is the first thing I check.

Looks good now
C:\>exiftool -config GPSQRCode.config -GPSQRCode -G1 -a -s y:\!temp\Test4.jpg
[Composite]     GPSQRCode                       : (Binary data 448 bytes, use -b option to extract)
Title: Re: qrencode config file
Post by: wywh on August 06, 2024, 11:11:12 AM
Quote from: StarGeek on August 06, 2024, 09:44:31 AMComposite GPS tags. Those tags should include the reference direction if it is in the file somewhere.

In images GPS is very verbose while in movies it is terse (-e does not generate composite tags)...

exiftool -a -G1 -s -n -e  -Location:All .
======== ./image.jpg
[GPS]           GPSVersionID                    : 2 3 0 0
[GPS]           GPSLatitudeRef                  : S
[GPS]           GPSLatitude                     : 36.6101
[GPS]           GPSLongitudeRef                 : W
[GPS]           GPSLongitude                    : 66.91515
[GPS]           GPSAltitudeRef                  : 0
[GPS]           GPSAltitude                     : 119.9
======== ./movie.mp4
[Keys]          GPSCoordinates                  : -36.6101 -66.91515 119.9


I like Composite:GPSPosition because it acts the same in images and movies which otherwise have different tags for GPS.

The only thing I dislike is that Composite:GPSPosition ignores altitude and puts it to Composite:GPSAltitude.

exiftool -a -G1 -s -n -Composite:GPSPosition -Composite:GPSAltitude .
======== ./image.jpg
[Composite]     GPSPosition                     : -36.6101 -66.91515
[Composite]     GPSAltitude                     : 119.9
======== ./movie.mp4
[Composite]     GPSPosition                     : -36.6101 -66.91515
[Composite]     GPSAltitude                     : 119.9

- Matti