png-image:   Library to view and modify PNG chunks.
png?
png->hash
hash->png
text-data->hash
ztxt-data->hash
itxt-data->hash
text-hash->data
ztxt-hash->data
itxt-hash->data
make-text-chunk
make-ztxt-chunk
make-itxt-chunk
make-text-hash
make-ztxt-hash
make-itxt-hash
bytes-crc32
bytes-adler32
8.12

png-image: Library to view and modify PNG chunks.🔗ℹ

Lehi Toskin

png-image will allow programmers to dissect a PNG image to view its contents separated by its chunks. This module provides all of the below procedures, even if they’re in separate files.

procedure

(png? img)  boolean?

  img : (or/c path-string? bytes?)
Checks if the given path or byte string is a valid PNG image.

procedure

(png->hash img)  (and/c hash? immutable?)

  img : png?
Given a valid PNG image, returns an immutable hash where each key is the name of a chunk (which is itself a hash). If a chunk may appear multiple times according to the PNG spec, then the chunk information is wrapped inside a list of hashes. In txt chunks, if the text has been deflated, it will be inflated in this step.

The chunk hashes have the keys '(type data length crc32).

procedure

(hash->png hsh)  bytes?

  hsh : hash?
Given a hash, returns a valid PNG image as a byte string. If converted from one form to the other, the resulting byte string may not be identical to the original bytes due to the ordering of the chunks, but all the chunks should be inside the final result. If the hash has iTXt chunks, the text data will be deflated if it exceeds 1024 bytes.

About text chunks:

* tEXt data hashes have the keys '(keyword text).

* zTXt data hashes have the keys '(keyword compression-method text).

* iTXt data hashes have the keys '(keyword compression-flag compression-method language-tag translated-keyword text).

* The only valid compression-method value is #"\0".

procedure

(text-data->hash bstr)  hash?

  bstr : bytes?

procedure

(ztxt-data->hash bstr)  hash?

  bstr : bytes?

procedure

(itxt-data->hash bstr)  hash?

  bstr : bytes?
Take an incomplete chunk that contains only the data and create a hash. In iTXt, if the data is longer than 1024 bytes, it will NOT be deflated here.

procedure

(text-hash->data hsh)  bytes?

  hsh : hash?

procedure

(ztxt-hash->data hsh)  bytes?

  hsh : hash?

procedure

(itxt-hash->data hsh)  bytes?

  hsh : hash?
Take an incomplete chunk hash and return incomplete data.

procedure

(make-text-chunk keyword [str])  bytes?

  keyword : string?
  str : string? = ""

procedure

(make-ztxt-chunk keyword [str])  bytes?

  keyword : string?
  str : string? = ""

procedure

(make-itxt-chunk keyword    
  [str    
  language-tag    
  translated-kw])  bytes?
  keyword : string?
  str : string? = ""
  language-tag : string? = ""
  translated-kw : string? = ""
Create a complete chunk with the keyword. In iTXt, if str exceeds 1024 bytes, it will be deflated. In zTXt, str will always be deflated.

procedure

(make-text-hash chunk)  hash?

  chunk : bytes?

procedure

(make-ztxt-hash chunk)  hash?

  chunk : bytes?

procedure

(make-itxt-hash chunk)  hash?

  chunk : bytes?
Create a complete hash from the complete chunk bytes. In iTXt, if the text from chunk is deflated, it will be inflated in this step. In zTXt, the text will always be deflated.

procedure

(bytes-crc32 bstr)  integer?

  bstr : bytes?
Calculates the CRC32 of the byte string and returns a decimal integer.

procedure

(bytes-adler32 bstr)  integer?

  bstr : bytes?
Calculates the ADLER32 of the byte string and returns a decimal integer.