Skip to main content

Module image

Module image 

Source
Expand description

image file helpers — port of LaTeXML::Util::Image Image helpers — port of LaTeXML::Util::Image.

Perl counterpart: lib/LaTeXML/Util/Image.pm.

Provides filesystem search for image candidates, minimal header-based image size detection (PNG / JPEG / EPS) and the graphicx sizer that converts keyval option strings into box dimensions. The Rust port is intentionally narrower than the Perl original — Image::Magick is not used at all; LaTeXML::Post::Graphics carries out any heavy-duty image operations in a post-processing pass.

Structs§

PostScriptBoxes
The DSC bounding-box comments of a PostScript file (Adobe DSC 3.0: %%BoundingBox:, %%HiResBoundingBox:, (atend)), as (llx, lly, urx, ury) in bp.

Enums§

GraphicContent
What a graphic file holds, by its first bytes: drawn (PDF, PostScript), so a converter renders it at a density, or a raster’s pixels (PNG, JPEG, GIF, TIFF, BMP, WebP), which -density does not resample.
GraphicxOp
One graphicx transformation, as compiled from the option string.
ImageSize
What read_image_size measures: a raster’s pixel count, or a PostScript file’s bounding box in bp — a physical size, which needs no resolution.

Functions§

apply_graphicx_ops
Apply a compiled transformation sequence to a natural size.
clear_image_size_memo
Clear the per-thread image size memos. Called at the start of every conversion, beside clear_kpsewhich_memo: a long-lived worker thread converts many papers, and a file may change between them.
graphic_content
GraphicContent of the file at path, whatever its name (a PDF or EPS saved as .pstex, cond-mat0603250’s loop.pstex); None when the head is none of them (a compressed .eps.gz among them).
graphicx_crop_rect
The pixel rectangle a trim/viewport op keeps of a w×h raster, as (x, y, width, height) from its top-left corner; None when the box keeps the whole image or no pixel of it. Port of Perl image_graphicx_complex’s trim/clip arm (Util/Image.pm L400-418): TeX measures the box from the lower-left corner and ImageMagick from the upper-left, and the box is clamped to the image, never padded. px_per_bp is the raster’s own resolution over 72 (DIVERGENCES #337: Perl divides by 72.27 and reads the resolution without its unit).
image_candidates
Perl: image_candidates($path) (Util::Image L43-57).
image_graphicx_sizer
Perl: image_graphicx_sizer($whatsit) (Util::Image L259-272).
natural_display_size_pt
The figure’s TRUE natural (typeset) size in TeX pt, for the VECTOR formats whose intrinsic size is a real physical dimension: a PDF page box, an EPS/PS %%BoundingBox (both bp), or an SVG’s lengths/viewBox. None for raster formats — a pixel count is not a physical size without a DPI — and when the geometry can’t be recovered.
natural_display_size_pt_of_candidates
natural_display_size_pt of the candidate the box is sized from: the first of a comma-joined candidates string (the <ltx:graphics candidates=…> attribute, resolved against source_dir) that any reader sizes (first_natural_size), None when that one is a raster — so a q.png before a q.eps gives no em size, as any raster does, rather than the eps’s size for the png pdflatex prints (review rev78z finding 1).
parse_bbox
Parse "llx lly urx ury" from a BoundingBox comment body.
parse_graphicx_options
Compile a graphicx option string into the transformation sequence.
pdf_image_resolution
\pdfimageresolution as pdftex.web:34511-34515 applies it to a raster stating no usable resolution: the register clamped to 0..65535, and 72 dpi when that is 0 (ext_xn_over_d(one_hundred_inch, x, 7200)).
raster_resolution_dpi
A raster’s own resolution in dots per inch, (x, y), as pdfTeX reads it to size an image: a PNG’s pHYs chunk (unit 1 is per metre), rounded to whole dpi, or a JPEG’s density from the segment right after SOI (jpeg_resolution_dpi) — pdflatex measures an 11811 px/m PNG at 300 dpi and a 118 px/cm JPEG at 299. None when the file states none, only an aspect ratio (unit 0), or one pdfTeX ignores for a raster of pixels (width, height; pdftex_raster_resolution): pdfTeX then takes \pdfimageresolution (raster_sizing_dpi). Reads the head only: both come before the pixels.
raster_sizing_dpi
The resolution pdfTeX sizes a raster of pixels at, as \pdfximage does (pdftex.web:34488-34515): its own (raster_resolution_dpi), else \pdfimageresolution (pdf_image_resolution), with pdfTeX’s Warning, when warn, if it ignores one the file states.
read_image_dimensions
Read image dimensions (width, height) in pixels from a file. Supports PNG, JPEG, and EPS (PostScript BoundingBox, its bp rounded to whole units).
read_image_size
The size of a PNG, JPEG or EPS/PS file, sniffed from its header (ImageSize), read once per path and conversion.
read_pdf_page_box
Read a PDF’s page box (width, height) in bp — CropBox (pdfTeX’s default), else MediaBox. Pure Rust, no external tool (this is what pdfTeX’s built-in reader does). Shared with LaTeXML::Post::Graphics.
read_pdf_page_box_corners
The page box read_pdf_page_box reads, as its corners [llx, lly, urx, ury] in bp — what pdfTeX’s \pdfximagebbox reports for an image (pdftex.web pdf_ximage_bbox).
read_pdf_page_count
The page count of a PDF, as pdfTeX’s \pdflastximagepages reports it after \pdfximage: the root /Type /Pages node’s /Count. Without a full parser, the root is the /Pages dictionary with the LARGEST /Count (intermediate nodes count only their subtree); raw bytes first, then the inflated object streams (PDF 1.5+, see read_pdf_page_box). A PDF with no /Pages dictionary at all falls back to counting /Type /Page objects.
read_postscript_boxes
See PostScriptBoxes; None when the file cannot be read.
read_postscript_size_bp
A PostScript file’s size in bp, as TeX reads it: the %%BoundingBox, graphics.sty’s \Gread@eps reading (\Gread@BBox, graphics.sty:52, read at :365-399; the hiresbb option, :56-57, aside) and epstopdf’s, which pdflatex then reads as the page; a %%HiResBoundingBox only when there is no %%BoundingBox (where TeX finds no size at all), as post reads the file (latexml_post graphics.rs read_postscript_bounding_box_full). None for an empty box. Until 78z the high-resolution box came first, rounded: a file with %%BoundingBox: 0 0 200 100 and %%HiResBoundingBox: 0.4 0.3 199.3 99.4 was 199bp x 99bp where latex and pdflatex make it 200.75pt x 100.375pt; hep-ex0703011’s eeggmet.eps carries a stale full-page %%HiResBoundingBox (612x792) beside its 540x522 %%BoundingBox.
read_svg_viewport_px
SVG viewport size in CSS px, the way a browser takes it: the root width/height (a unitless value is CSS px), falling back to the viewBox only when the lengths are absent or relative (%). None when neither is usable, so the caller omits the dimensions and lets the browser size it.
svg_attr_len_px
An SVG length attribute in CSS px. A unitless value is user units, i.e. px. None for anything that isn’t an absolute length (%, em, ex, …) — those are resolved against a viewport we don’t have, so the caller must fall back to the viewBox rather than treat the bare number as pixels.
svg_attr_value
Value of the name="…" / name='…' attribute in an XML start tag.
svg_root_tag
The root <svg …> start tag within head, quote-aware so a > inside an attribute value doesn’t end the tag early. Skipping to <svg also steps over the <?xml …?> prolog, comments and any DOCTYPE — otherwise the prolog’s ?> would be mistaken for the end of the start tag.
svg_viewport_px
read_svg_viewport_px of an SVG’s text (its head suffices) already in memory.
to_bp
A TeX/graphicx length in bp. Port of Perl to_bp + %BP_conversions (Util/Image.pm L198-210), including its true-prefix strip (truept) and its “unknown unit counts as bp” fallback. A value that is not a length at all yields 1, exactly as Perl’s else { return 1 } does.
xml_start_tag
The start tag that text begins with, up to (not including) its >, quote-aware.