gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.83k stars 7.54k forks source link

Support for converting PNM files to images #11388

Open Winterhuman opened 1 year ago

Winterhuman commented 1 year ago

Netpbm defines a set of plaintext and binary file types which can be converted into images, as an example:

P3
1 1
255
255 0 0

ImageMagick's convert file.txt image.png command can be used to see it in action, just make sure there's a blank line at the end of the file.

Being able to use Portable Anymap Format (PNM) files as the input (and potentially output too) for convertTo and related functions would be amazing, since it would enable programmatically generating images from within Hugo. Example use-case: Generating an image based on the value of .Pages.

Right now, this can be achieved by setting an environment variable to the Hugo variable's value, and then using a separate script to generate and convert the PNM files, however, Hugo doesn't support executing external scripts upon running hugo so this isn't very convenient if you have many images which change often.

Existing Go library: https://github.com/spakin/netpbm (might be too old, looks like libraries for separate types such as PPM are more up-to-date: https://github.com/lmittmann/ppm)

bep commented 1 year ago

Example use-case: Generating an image based on the value of .Pages.

What type of images do you think about here?

Winterhuman commented 1 year ago

Something like what I do with this script. Where it takes a number for the filled-in pixel count (.Pages), finds the minimum dimensions for a given aspect ratio and the pixel count, and then simply fills the number of pixels passed to the script