DpiUtil

object DpiUtil

Stateless utility for reading and writing DPI (dots per inch) metadata in image files.

Supports PNG (pHYs chunk) and JPEG (app0JFIF segment) metadata formats. Falls back to a default of 300 DPI when metadata is missing or unreadable.

Functions

Link copied to clipboard
fun readImageDPI(imageFile: File, logSignature: String = DEFAULT_LOG_SIGNATURE): Int

Reads DPI metadata from an image file.

fun readImageDPI(imageBytes: ByteArray, logSignature: String = DEFAULT_LOG_SIGNATURE): Int

Reads DPI metadata from image bytes.

Link copied to clipboard
fun writeImageWithDPI(image: BufferedImage, outputFile: File, dpi: Int = DEFAULT_DPI, logSignature: String = DEFAULT_LOG_SIGNATURE)

Writes a BufferedImage to a PNG file with proper DPI metadata. This ensures Tesseract gets the correct resolution information.