jpeg(n)

πŸ“¦
version 2.0 Β· 2 versions
, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

🌸 jpeg β€” the manual, but make it a group chat 🌸

okay bestie, sit down, hydrate, because we're about to talk about JPEG and honestly? it's giving main character energy. this is the jpeg(n) page from tcllib, section n, and it's literally all about JPEG querying and manipulation of meta data. no cap. ✨


✨ NAME ✨

jpeg β€” JPEG querying and manipulation of meta data πŸŽ€


πŸ’… SYNOPSIS πŸ’…

first things first, the requirements, because we are not doing this without them:

package require Tcl 8.5 9

package require jpeg ?0.7?

and then the actual girlies, the whole squad of commands:

::jpeg::isJPEG file

::jpeg::imageInfo file

::jpeg::dimensions file

::jpeg::getThumbnail file

::jpeg::getExif file ?section?

::jpeg::getExifFromChannel channel ?section?

::jpeg::formatExif keys

::jpeg::exifKeys

::jpeg::removeExif file

::jpeg::stripJPEG file

::jpeg::getComments file

::jpeg::addComment file text...

::jpeg::removeComments file

::jpeg::replaceComment file text

::jpeg::debug file

::jpeg::markers channel

πŸ¦‹ DESCRIPTION πŸ¦‹

so this package gives you commands to query and modify JPEG images. and if you were wondering what JPEG even stands for β€” it's Joint Photography Experts Group, a whole standard for the lossy compression of photographical images. it is specified at LINK_HERE.

(yeah. LINK_HERE. that's what the original says and we do not edit the ancestors. πŸ™ˆ)


πŸ‘‘ COMMANDS πŸ‘‘

::jpeg::isJPEG file

returns a boolean value telling you whether file is a JPEG image or not. simple. clean. a vibe check for files, honestly. πŸ”₯

::jpeg::imageInfo file

returns a dictionary with the keys version, units, xdensity, ydensity, xthumb, and ythumb. those values are the associated properties of the JPEG image in file. throws an error if file is not a JPEG image. 😭

::jpeg::dimensions file

returns the dimensions of the JPEG file as a list of the horizontal and vertical pixel count. throws an error if file is not a JPEG image. πŸ“

::jpeg::getThumbnail file

this one returns the binary thumbnail image data if a JPEG thumbnail is included in file, and the empty string otherwise. and listen β€” it is possible to include thumbnails in formats other than JPEG, although that is not common. the command finds thumbnails encoded in either the JFXX or EXIF segments of the JPEG information, and if both are present, the EXIF thumbnail takes precedence. throws an error if file is not a JPEG image.

    set fh [open thumbnail.jpg w+]
    fconfigure $fh -translation binary -encoding binary
    puts -nonewline $fh [::jpeg::getThumbnail photo.jpg]
    close $fh

::jpeg::getExif file ?section?

section must be one of main or thumbnail, and the default is main. returns a dictionary containing the EXIF information for the specified section. like, for example:

    set exif {
  Make     Canon
  Model    {Canon DIGITAL IXUS}
  DateTime {2001:06:09 15:17:32}
    }

throws an error if file is not a JPEG image.

::jpeg::getExifFromChannel channel ?section?

this command is as per ::jpeg::getExif, except that it uses a previously opened channel. channel should be a seekable channel and section is as described in the documentation of ::jpeg::getExif.

Note: the jpeg parser expects that the start of the channel is the start of the image data. if you're working with an image embedded in a container file format, it may be necessary to read the jpeg data into a temporary container: either a temporary file or a memory channel. 🫢
Attention: it is the responsibility of the caller to close the channel after its use. 🚨

::jpeg::formatExif keys

takes a list of key-value pairs as returned by getExif and formats many of the values into a more human readable form. as few as one key-value may be passed in β€” the entire exif is not required. πŸ’–

    foreach {key val} [::jpeg::formatExif [::jpeg::getExif photo.jpg]] {
        puts "$key: $val"
    }

    array set exif [::jpeg::getExif photo.jpg]
    puts "max f-stop: [::jpeg::formatExif [list MaxAperture $exif(MaxAperture)]]

::jpeg::exifKeys

returns a list of the EXIF keys which are currently understood. heads up: there may be keys present in getExif data that are not understood, and those keys will appear in a 4 digit hexadecimal format. iykyk. πŸ’…

::jpeg::removeExif file

removes the Exif data segment from the specified file and replaces it with a standard JFIF segment. throws an error if file is not a JPEG image. bye exif bestie πŸ‘‹

::jpeg::stripJPEG file

removes all metadata from the JPEG file, leaving only the image. this includes comments, EXIF segments, JFXX segments, and application specific segments. throws an error if file is not a JPEG image. she's naked now, that's the whole point. πŸ’€

::jpeg::getComments file

returns a list containing all the JPEG comments found in the file. throws an error if file is not a valid JPEG image. πŸ“

::jpeg::addComment file text...

adds one or more plain text comments to the JPEG image in file. throws an error if file is not a valid JPEG image. ✍️

::jpeg::removeComments file

removes all comments from the file specified. throws an error if file is not a valid JPEG image. 🧹

::jpeg::replaceComment file text

replaces the first comment in the file with the new text. this is merely a shortcut for ::jpeg::removeComments and ::jpeg::addComment. throws an error if file is not a valid JPEG image. ✨

::jpeg::debug file

prints everything we know about the given file in a nice format. πŸ› no notes, she's an icon.

::jpeg::markers channel

okay so this one is an internal helper command β€” we document it for use by advanced users of the package. the argument channel is an open file handle positioned at the start of the first marker (usually 2 bytes). the command returns a list with one element for each JFIF marker found in the file. each element consists of a list of the marker name, its offset in the file, and its length. the offset points to the beginning of the sections data, not the marker itself. the length is the length of the data from the offset listed to the start of the next marker. πŸ€“


😭 LIMITATIONS 😭

the tea, unsweetened, no filter:

  • can only work with files
  • cant write exif data
  • gps exif data not parsed
  • makernote data not yet implemented

🫢 BUGS, IDEAS, FEEDBACK 🫢

this document, and the package it describes, will undoubtedly contain bugs and other problems. please report such in the category jpeg of the Tcllib Trackers at [http://core.tcl.tk/tcllib/reportlist]. please also report any ideas for enhancements you may have for either the package and/or the documentation. we want the ideas, we want them all. 🌈

when proposing code changes, please provide unified diffs, i.e the output of diff -u. πŸ“Ž

note further that attachments are strongly preferred over inlined patches. attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. slay, thank you, mwah. πŸ’‹


⭐ KEYWORDS ⭐

comment, exif, image, jfif, jpeg, thumbnail


πŸŽ€ CATEGORY πŸŽ€

File formats


Copyright (c) 2004-2005, Code: Aaron Faupell <afaupell@users.sourceforge.net>
Copyright (c) 2007, Code:  Andreas Kupries <andreas_kupries@users.sourceforge.net>
Copyright (c) 2004-2009, Doc:  Andreas Kupries <andreas_kupries@users.sourceforge.net>
Copyright (c) 2011, Code: Pat Thoyts <patthoyts@users.sourceforge.net>

and that's the whole page, bestie. brought to you by tcllib, version 0.7, and the jpeg(n) manual β€” go forth and query some metadata. periodt. πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from