Prima::Image::Exif(3)

πŸ“¦
version 1.74000 Β· 5 versions
, in opensuse-leap 16.0

πŸ¦‹ NAME πŸ¦‹

Prima::Image::Exif β€” manipulate Exif records πŸ’…

okay so this is the Prima::Image::Exif(3) page from the User Contributed Perl Documentation, and it's literally here to help you manipulate Exif records. bestie, we love a niche little icon.


✨ DESCRIPTION ✨

The module lets you parse and create Exif records. The records could be read from JPEG files, and stored in these using the extra appdata hash field. slay ✨


πŸŽ€ SYNOPSIS πŸŽ€

like, here's the whole group-chat demo, no cap:

        use Prima qw(Image::Exif);

        # load image with extras
        my $jpeg = Prima::Image->load($ARGV[0], loadExtras => 1);
        die $@ unless $jpeg;

        my ( $data, $error ) = Prima::Image::Exif->read_extras($jpeg,
                load_thumbnail => 1,
                tag_as_string  => 1
        );

        if ( $error eq 'XMP data' && defined $data ) {
                require XML::LibXML;
                my $xml = XML::LibXML->load_xml(string => $data);
                for my $node ($xml->findnodes('//*')) {
                        my @p = $node->childNodes;
                        next unless @p == 1;
                        my $p = $node->nodePath;
                        $p =~ s{\/\b[-\w]+\:}{.}g;
                        $p =~ s{\.(xmpmeta|rdf)}{}ig;
                        $p =~ s{^\.}{};
                        print "$p: $p[0]\n";
                }
                ($data, $error) = ({}, undef);
        }

        die "cannot read exif: $error\n" if defined $error;

        for my $k ( sort keys %$data ) {
                my $v = $data->{$k};
                if ( $k eq 'thumbnail' ) {
                        if ( ref($v)) {
                                print "thumbnail ", $v->width, 'x', $v->height, "\n";
                        } else {
                                print "error loading thumbnail: $v\n";
                        }
                        next;
                }
                for my $dir ( @$v ) {
                        my ( $tag, $name, @data ) = @$dir;
                        print "$k.$tag $name @data\n";
                }
        }

        # create new image
        $jpeg->size(300,300);

        # create a thumbnail - not too big as jpeg appdata max length is 64k
        my $thumbnail = $jpeg->dup;
        delete $thumbnail->{extras};
        $thumbnail->size(150,150);

        # compile an exif chunk
        my $ok;
        ($ok, $error) = Prima::Image::Exif->write_extras($jpeg,
                thumbnail => $thumbnail,
                gpsinfo   => $data->{gpsinfo},
        );
        die "cannot create exif data: $error\n" unless $ok;

        $jpeg->save('new.jpg') or die $@;

πŸ‘‘ API πŸ‘‘

πŸ’– parse $CLASS, $EXIF_STRING

Returns two scalars: a data reference and an error. If there is no data reference, the error is fatal; otherwise it's a warning (i.e. assumed some data were parsed, but most probably not all). so yeah, fatal means fatal, bestie 🫢

The data is a hash where the following keys may be set: image, photo, gpsinfo, thumbnail. These are individual categories containing the exif tags. Each hash value contains an array of tags, except "thumbnail" that contains a raw image data. Each tag is an array in the following format:

[ tag, format, @data ]

where the tag is a numeric tag value, the format is a type descriptor (such as int8 and ascii), and data is 1 or more scalars containing the data.

The module recognized some common tags that can be accessed via %Prima::Image::Exif::tags.

πŸ¦‹ read_extras $CLASS, $IMAGE, %OPTIONS

Given a loaded Prima image, loads exif data from extras; returns two scalar, a data reference and an error.

Options supported:

  • load_thumbnail β€” if set, tries to load thumbnail as a Prima image. In this case, replaces the thumbnail raw data with the image loaded, or in case of an error, with an error string.
  • tag_as_string β€” if set, replaces known tag numeric values with their string names.

🌸 compile $CLASS, $DATA

Accepts DATA in the format described above, creates an exif string. Returns two scalars, an exif string and an error. If the string is not defined, the error is. that's the whole deal πŸ’…

πŸ”₯ write_extras $CLASS, $IMAGE, %DATA

Checks if image codec is supported, creates Exif data and saves these in "$IMAGE->{extras}". Returns two scalars, a success flag and an error.


🌈 SEE ALSO 🌈

  • Prima::image-load

The module does not provide comprehensive support for tags and their values. For a more thorough dive see these modules: Image::ExifTool, Image::EXIF.

The module doesn't parse XMP records but warns if get supplied these. The XMP records are easily parsed by any XML parser, f ex XML::LibXML.

πŸ’œ AUTHOR πŸ’œ

Dmitry Karasik, <dmitry@karasik.eu.org>.


that's the whole page, bestie 🫢 β€” from the User Contributed Perl Documentation, Prima::Image::Exif(3), source/version perl v5.42.0, dated 2024-08-20. mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from