jpeg(3tcl)
π jpeg β JPEG querying and manipulation of meta data π
okay bestie, welcome to jpeg(3tcl), the Tcllib manual page for peeking at and poking JPEG files. she's a whole vibe, she's giving "I know everything about your photos", and we're gonna go through her top to bottom, no skips, no cap. π
β¨ SYNOPSIS β¨
package require Tcl 8.5 9
package require jpeg ?0.7?
::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
like yes, that's the whole friend group right there. π
πΈ DESCRIPTION πΈ
so this package is your little toolbox for querying and modifying JPEG images. and for the uninitiated: JPEG stands for Joint Photography Experts Group β yes that's literally what it's called β and it's a standard for the lossy compression of photographical images. it's specified at LINK_HERE. π¦
π COMMANDS π
π ::jpeg::isJPEG file
returns a boolean value telling you if file is a JPEG image. that's it, that's the whole job. she just checks the vibe. β
π ::jpeg::imageInfo file
returns a dictionary with 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. she's not playing about it. π€
π ::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 procedure returns the binary thumbnail image data if a JPEG thumbnail is included in file, and the empty string otherwise. and real talk β note that it's 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. if both are present, the EXIF thumbnail takes precedence. π
throws an error if file is not a JPEG image.
here's how you'd actually use her, bestie:
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. the default is main. returns a dictionary containing the EXIF information for the specified section. 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 resonsibility of the caller to close the channel after its use. yes, we said it with the typo, that's how she lives. π₯
π ::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)]]
(yes, that last line is exactly as written. we keep the facts exact, even when the facts are quirky. β¨)
π ::jpeg::exifKeys
returns a list of the EXIF keys which are currently understood. there may be keys present in getExif data that are not understood β 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.
π ::jpeg::stripJPEG file
removes all metadata from the JPEG file, leaving only the image. that includes comments, EXIF segments, JFXX segments, and application specific segments. she strips it down to the bare fit. π
throws an error if file is not a JPEG image.
π ::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. full info dump, main character energy, no secrets. π
π ::jpeg::markers channel
this 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 π
okay so, being honest with you bestie, she's got some limits:
- can only work with files
- cant write exif data
- gps exif data not parsed
- makernote data not yet implemented
we love her anyway. π
π 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 [http://core.tcl.tk/tcllib/reportlist](http://core.tcl.tk/tcllib/reportlist). please also report any ideas for enhancements you may have for either package and/or documentation. we're listening, fr fr. π
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. β¨
π·οΈ KEYWORDS π·οΈ
comment, exif, image, jfif, jpeg, thumbnail
π CATEGORY π
File formats
Β©οΈ COPYRIGHT Β©οΈ
- 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!! π this gem lives in tcllib, version 0.7, and it's the jpeg(3tcl) manual page β go forth and interrogate your photos, you absolute icon. πβ¨π¦
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- 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>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms