tiff(3tcl)

πŸ“¦
version 2.0 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ NAME ✨

tiff β€” the whole entire vibe of reading TIFFs, writing TIFFs, and poking at all their metadata πŸ’…


🌸 SYNOPSIS 🌸

package require Tcl 8.5 9

package require tiff ?0.2.3?

::tiff::isTIFF file

::tiff::byteOrder file

::tiff::numImages file

::tiff::dimensions file ?image?

::tiff::imageInfo file ?image?

::tiff::entries file ?image?

::tiff::getEntry file entry ?image?

::tiff::addEntry file entry ?image?

::tiff::deleteEntry file entry ?image?

::tiff::getImage file ?image?

::tiff::writeImage image file ?entry?

::tiff::nametotag names

::tiff::tagtoname tags

::tiff::debug file

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so bestie, this package hands you a whole lil toolbox for querying, modifying, reading, and writing TIFF images. no cap 🫢

TIFF stands for Tagged Image File Format and it's a standard for lossless storage of photographical images and associated metadata. the full spec lives at http://partners.adobe.com/public/developer/tiff/index.html if you're feeling brave πŸ“–

here's the tea: multiple images can live inside a single TIFF file. that's why all these functions take an optional ?image? argument β€” it's so you can reach images that aren't the first one. slay.

and the data inside a TIFF image? it's stored as a series of tags, and every tag has a numerical value. those get represented either as a 4 digit hexadecimal format or as a string name. if you want the full reference on defined tags and what they mean, it's at http://www.awaresystems.be/imaging/tiff/tifftags.html 🌈


πŸ‘‘ COMMANDS πŸ‘‘

  • ::tiff::isTIFF file β€” returns a boolean value telling you if file is a TIFF image. yes/no, in or out, simple πŸ’–
  • ::tiff::byteOrder file β€” returns either big or little. and if file isn't a TIFF image? it throws an error, no mercy 😀
  • ::tiff::numImages file β€” returns the number of images in file. also throws an error if file isn't a TIFF image.
  • ::tiff::dimensions file ?image? β€” returns the dimensions of image number ?image? in file, as a list of the horizontal and vertical pixel count. yep, throws an error if file isn't a TIFF image πŸ“
  • ::tiff::imageInfo file ?image? β€” returns a dictionary with these keys: ImageWidth, ImageLength, BitsPerSample, Compression, PhotometricInterpretation, ImageDescription, Orientation, XResolution, YResolution, ResolutionUnit, DateTime, Artist, and HostComputer. the values are the associated properties of the TIFF ?image? in file. ngl some values may come back empty if that tag just isn't present in the file, and that's fine, it's not a bug 🫠
puts [::tiff::imageInfo photo.tif]

ImageWidth 686 ImageLength 1024 BitsPerSample {8 8 8} Compression 1
PhotometricInterpretation 2 ImageDescription {} Orientation 1
XResolution 170.667 YResolution 170.667 ResolutionUnit 2 DateTime {2005:12:28 19:44:45}
Artist {} HostComputer {}

lowkey there is nothing special about these tags β€” this is simply a convenience procedure which calls getEntry with common entries. and yeah, it throws an error if file isn't a TIFF image πŸ’€

  • ::tiff::entries file ?image? β€” returns a list of all entries in the given file and ?image?, in hexadecimal format. Throws an error if file isn't a TIFF image πŸ“‹
  • ::tiff::getEntry file entry ?image? β€” returns the value of entry from image ?image? in the TIFF file. entry may be a list of multiple entries. if an entry doesn't exist, you get back an empty string, no drama. and yup β€” throws an error if file isn't a TIFF image.
set data [::tiff::getEntry photo.tif {0131 0132}]
puts "file was written at [lindex $data 0] with software [lindex $data 1]"
  • ::tiff::addEntry file entry ?image? β€” adds the specified entries to the image named by ?image? (default 0), or optionally all. entry must be a list where each element is a list of tag, type, and value. heads up: if a tag already exists, it is overwritten β€” bye bye old data πŸ‘‹
::tiff::addEntry photo.tif {{010e 2 "an example photo"} {013b 2 "Aaron F"}}

the data types are defined as follows:

  1. 1 β€” BYTE (8 bit unsigned integer)
  2. 2 β€” ASCII
  3. 3 β€” SHORT (16 bit unsigned integer)
  4. 4 β€” LONG (32 bit unsigned integer)
  5. 5 β€” RATIONAL
  6. 6 β€” SBYTE (8 bit signed byte)
  7. 7 β€” UNDEFINED (uninterpreted binary data)
  8. 8 β€” SSHORT (signed 16 bit integer)
  9. 9 β€” SLONG (signed 32 bit integer)
  10. 10 β€” SRATIONAL
  11. 11 β€” FLOAT (32 bit floating point number)
  12. 12 β€” DOUBLE (64 bit floating point number)

and yes, it throws an error if file isn't a TIFF image 🌟

  • ::tiff::deleteEntry file entry ?image? β€” deletes the specified entries from the image named by ?image? (default 0), or optionally all. Throws an error if file isn't a TIFF image πŸ—‘οΈ
  • ::tiff::getImage file ?image? β€” returns the name of a Tk image containing the image at index ?image? from file. Throws an error if file isn't a TIFF image, or if image is an unsupported format. the supported formats are uncompressed 24 bit RGB and uncompressed 8 bit palette πŸ–ΌοΈ
  • ::tiff::writeImage image file ?entry? β€” writes the contents of the Tk image image to a tiff file file. files are written in the 24 bit uncompressed format, with big endian byte order. additional entries to be added to the image may be specified, in the same format as tiff::addEntry ✍️
  • ::tiff::nametotag names β€” returns a list with names translated from string to 4 digit format. any 4 digit names in the input are passed through unchanged. and if a string doesn't have a defined tag name? it will throw an error 😭
  • ::tiff::tagtoname tags β€” returns a list with tags translated from 4 digit to string format. if a tag doesn't have a defined name, it's passed through unchanged, no problem πŸ’œ
  • ::tiff::debug file β€” prints everything we know about the given file in a nice format. it's giving main character energy, honestly πŸ”

πŸŽ€ VARIABLES πŸŽ€

the mapping of 4 digit tag names to string names uses the array ::tiff::tiff_tags. the reverse mapping uses the array ::tiff::tiff_sgat. iykyk ✨


🌈 LIMITATIONS 🌈

  1. cannot write exif ifd πŸ™ˆ
  2. reading limited to uncompressed 8 bit rgb and 8 bit palletized images
  3. writing limited to uncompressed 8 bit rgb
not me pointing out that these are real limits, bestie. know them before you get surprised πŸ’€

πŸ’œ BUGS, IDEAS, FEEDBACK πŸ’œ

this document, and the package it describes, will undoubtedly contain bugs and other problems. it's not being shady, it's just the truth fr fr.

please report such in the category tiff of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. please also report any ideas for enhancements you may have for either package and/or documentation 🌸

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 ⭐

image, tif, tiff


πŸ“ CATEGORY πŸ“

File formats


Copyright (c) 2005-2006, Aaron Faupell <afaupell@users.sourceforge.net>


okay that's the whole page, bestie πŸŽ€ this one shipped as part of tcllib, version 0.2.3, and it's been iconic since forever. go read some tags, slay, periodt πŸ‘‘

πŸ“¦ where this page comes from