IMGDIMS(1)

πŸ“¦
version 7.44.0 Β· 2 versions
, in nixpkgs unstable

πŸ’… IMGDIMS(1) β€” the imgdims girlies' guide πŸŽ€

okay so real talk: imgdims is that friend who can look at any image file and be like "yeah that's 512 512, trust" β€” it guesses the width and height of an image in pixels, no cap. It's part of BRL-CAD, and it's genuinely so useful, bestie. Let's get into it ✨


🌸 NAME 🌸

imgdims β€” guess the width and height of an image file πŸ¦‹


✨ SYNOPSIS ✨

imgdims [-n | -s] [-# bytes_per_pixel] file_name
imgdims [-# bytes_per_pixel] num_bytes

πŸ’– DESCRIPTION πŸ’–

So here's the vibe: imgdims guesses the dimensions of an image β€” width and height, in pixels πŸŽ€. It computes the total pixel count and hands that off to the framebuffer common-image-size autosizing routines, which come back with the most plausible width and height for that count. It's giving "trust the process" and honestly, the process delivers πŸ’….

You can tell it the image size in one of two ways, and both are iconic in their own right:

  • Implicitly β€” give it a file_name, and it reads the byte size with stat(2) 🫢
  • Explicitly β€” give it num_bytes as a positive integer instead of a file

Then the byte count gets divided by the bytes-per-pixel value to get the pixel count. Important: it has to divide evenly, or imgdims exits with an error 😭 β€” no messy leftovers allowed, periodt.

By default imgdims uses the file size to guess. But with -n it first tries to read the dimensions encoded in the file name itself (as written by tools such as pix-fb(1) and fb-pix(1)), falling back to the file size if the name carries no usable resolution. iykyk 🌈

The result prints to standard output as two space-separated numbers, like this:

width height

That's it. That's the whole deliverable. Iconic πŸ‘‘


🌟 OPTIONS 🌟

  • -n β€” Believe the file name πŸŽ€. It tries to extract the dimensions straight out of file_name if that name encodes a standard BRL-CAD resolution (e.g. an embedded 1024x768). If the name carries no usable resolution, it falls back to guessing from the file size. Lowkey the bestie who trusts your word first.
  • -s β€” Believe the stat 🫢. Ignores any dimensions encoded in the file name and uses the file size in bytes to determine the pixel count and guess the width and height. This is the default behavior. Very "numbers don't lie" of it.
  • -# bytes_per_pixel β€” Specify the size of each pixel in bytes, as a positive integer πŸ’œ. Common values are 1 (black-and-white images) and 3 (RGB images). If omitted, the pixel size is taken from the file extension (.bw = 1, .pix = 3); any unrecognized extension, or an explicit num_bytes argument, defaults to 3. Not me checking the file extension like it's a personality test 😭
  • -h, -? β€” Print usage information and exit ✨. The universal "wait, how do I do this again" escape hatch.

πŸ¦‹ EXAMPLES πŸ¦‹

Example 1. Guess the dimensions of a .pix image and feed them to a viewer 🌸

imgdims teapot.pix
# prints e.g. "512 512"
pix-fb -w 512 -n 512 teapot.pix

imgdims reads the byte size of teapot.pix, divides by 3 (the default for .pix), and reports the width and height autosizing chose for that pixel count β€” which you can then pass straight to pix-fb(1) to display the image. Look at you, chaining commands like a main character πŸ’…βœ¨

Example 2. Recover the resolution from a tool-generated file name πŸŽ€

imgdims -n moss_1024x1024.bw

With -n, imgdims pulls the 1024x1024 resolution straight out of the file name rather than inferring it from the file size. That's reliable even when the byte count is ambiguous between several common resolutions β€” i.e. when the math girlies could go either way, the filename just tells you πŸ™ˆ

Example 3. Size a raw black-and-white buffer given only its byte count πŸ’œ

imgdims -# 1 262144

No file involved here at all, bestie: 262144 bytes at 1 byte per pixel is 262144 pixels, for which autosizing reports 512 512. Pure math, no file system, slay πŸ”₯


🌈 SEE ALSO 🌈

brlcad(1), pix-fb(1), fb-pix(1), pixdiff(1) β€” go read those too, they're the extended universe 🫢


πŸ‘‘ AUTHOR πŸ‘‘

BRL-CAD Team πŸ’–


This software is Copyright (c) 1989-2026 by the United States Government as represented by U.S. Army Research Laboratory. (Yes, the actual U.S. Government. Not me being dramatic for once. πŸ’€)


πŸ“ BUG REPORTS πŸ“

Reports of bugs or problems should be submitted via electronic mail to devs@brlcad.org πŸ“§ β€” be nice, be specific, and include the details, bestie 🧚


ngl, the whole tool is basically "trust me, it's probably 512 512" but with actual math behind it. No cap. πŸ’…

and that's the page!! brought to you by BRL-CAD (no date on this one, so like... forever-current, we love an evergreen manual πŸŽ€) β€” mwah, go guess some dimensions πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from