ImageMagick

Started by cameyo, March 07, 2022, 12:49:15 PM

Previous topic - Next topic

cameyo

With ImageMagick is possible to create an image from within newLISP.

ImageMagick : https://imagemagick.org/">https://imagemagick.org/

The following command of ImageMagick creates an image "image.png" from a text file "pixels.txt":



convert pixels.txt image.png



The following command of ImageMagick creates an image "image.png" (with a white background) from a text file "pixels.txt":



convert pixels.txt -background white -flatten image.png



The structure of text file is this:



# ImageMagick pixel enumeration: 4,4,255,rgba

0,0: (187,102,127,128)

0,1: ( 51,153,127,10)

0,2: (204,102,127,255)

0,3: ( 68,153,127,128)

1,1: ( 51,153,127,200)

1,2: (204,102,127,255)

1,3: ( 68,153,127,255)

2,0: (187,102,127,150)

2,1: ( 51,153,127,128)

2,2: (204,102,127,45)

3,0: (187,102,127,255)

3,1: ( 51,153,127,255)

3,2: (204,102,127,150)



The first line (header) of the image is packed with the basic information about the image.

The information consists of:

File Magic: The image header defines this file as a the special IM text image format (ImageMagick pixel enumeration:)

Image Size: The next two numbers (4,4) define the size of the image contained in this file. Multiplying these numbers together will also tell you how many lines should follow the header to fully define the image.

MaxValue: The last number in the header defines the 'maximum value' of the image data that is possible. In the above examples this was '255' which is a result of using a 8 bit depth.

Colorspace: The last item in the header defines the colorspace of the data that follows. If the image contained any transparency, a final letter 'a' (for alpha) is also appended to the colorspace name, and an extra column of numbers added between parenthesis.



You do not need to define all the pixels in the image.

In fact you do not even need to have the pixels in the correct order.

ImageMagick will just read each pixel defining line in turn, and 'draw' it onto a blank image canvas.

More information at:

https://legacy.imagemagick.org/Usage/files">https://legacy.imagemagick.org/Usage/files



To create an image from within newLISP:



(exxec "convert pixels.txt image.png")



I have used this to create images of clifford attractor.