justgook/elm-image/5.0.0

Image.Advanced

Image Info

source : Image -> Source

Get image type

type Source
= Png
| Bmp
| Gif
| Code

Possible image decoded type

Manipulations

map : (Int -> Int) -> Image -> Image

Apply a function on every pixel in an image.

get : Int -> Int -> Int -> Int -> Image -> Image

Returns an Image representing the underlying pixel data for a specified portion of the Image.

region =
    Image.get sx sy sw sh image
  • sx The x-axis coordinate of the top-left corner of the rectangle from which the Image will be extracted.
  • sy The y-axis coordinate of the top-left corner of the rectangle from which the Image will be extracted.
  • sw The width of the rectangle from which the Image will be extracted. Positive values are to the right, and negative to the left.
  • sh The height of the rectangle from which the Image will be extracted. Positive values are down, and negative are up.
  • image The source image to select pixels from.
  • region An Image containing the image data for the rectangle of the image specified. The coordinates of the rectangle's top-left corner are (sx, sy), while the coordinates of the bottom corner are (sx + sw, sy + sh).
put : Int -> Int -> Image -> Image -> Image

Paints data from the given Image onto the other Image.

newImage =
    Image.put dx dy imageFrom imageTo
  • imageData An Image containing the array of pixel values.
  • dx Horizontal position (x coordinate) at which to place the image data in the destination Image.
  • dy Vertical position (y coordinate) at which to place the image data in the destination Image.
eval : Image -> Image

When decoding images they are decoded in lazy way (real decoding is postponed until data is needed) this function evaluates postponed decode, useful if you need to encode multiple images from same source.

mirror : Bool -> Bool -> Image -> Image

Mirror image horizontally or/and vertically

newImage =
    Image.mirror x y image

Custom Encoding

toPng32 : Image -> Bytes

Encode image into True color with alpha PNG image

toBmp24 : Image -> Bytes

Encode image into BMP24

toBmp32 : Image -> Bytes

Encode image into BMP32

Note: Using BMP 32bit is discouraged due to lack of proper support across browsers

toGIF89a : Image -> Bytes

Encode image into GIF89a

Note:

  1. Gif supports only 256 colors in palette - if image have more that 256 colors, all colors that exceed 256 will become first color in palette

  2. Gif supports only fully transparent color, all colors that isn't fully transparent (alpha > 0) will be flatted to it color