Skip to documentation
DocumentationAll documentsEnglish

IMGDIMS(1)

NAME

imgdims - guess the width and height of an image file

On this page

SYNOPSIS

imgdims [-n | -s] [-# _bytes_per_pixel_] _file_name_
imgdims [-# _bytes_per_pixel_] _num_bytes_

DESCRIPTION

imgdims guesses the dimensions (width and height in pixels) of an image. The total pixel count is computed and handed to the framebuffer common-image-size autosizing routines, which return the most plausible width and height for that count.

The image size may be specified either implicitly, by giving a file_name whose byte size is read with stat(2), or explicitly, by giving num_bytes as a positive integer instead of a file. The byte count is divided by the bytes-per-pixel value to obtain the pixel count; it must divide evenly or imgdims exits with an error. By default imgdims uses the file size to guess; with -n it first tries to read the dimensions encoded in the file name (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.

The result is printed to standard output as two space-separated numbers, "width height".

OPTIONS

-n

Believe the file name. Try to extract the dimensions directly from the file_name if it encodes a standard BRL-CAD resolution (e.g. an embedded "1024x768"). If the name carries no usable resolution, fall back to guessing from the file size.

-s

Believe the stat. Ignore any dimensions encoded in the file name and use the file size in bytes to determine the pixel count and guess the width and height. This is the default behavior.

-# 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.

-h, -?

Print usage information and exit.

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 can then be passed to pix-fb(1) to display the image.

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, which is reliable even when the byte count is ambiguous between several common resolutions.

Example 3. Size a raw black-and-white buffer given only its byte count
imgdims -# 1 262144

No file is involved here: 262144 bytes at 1 byte per pixel is 262144 pixels, for which autosizing reports "512 512".

SEE ALSO

brlcad(1), pix-fb(1), fb-pix(1), pixdiff(1)

AUTHOR

BRL-CAD Team

This software is Copyright (c) 1989-2026 by the United States Government as represented by U.S. Army Research Laboratory.

BUG REPORTS

Reports of bugs or problems should be submitted via electronic mail to devs@brlcad.org