justgook / elm-image / Image


type alias Image =
Internal.ImageData.Image

Data Model representing Image data, that can be used to create image, or convert primitives to use image pixels as data

Decoding

decode : Bytes -> Maybe Image

Convert blob of image (png or bmp) into Image

import Http

type Msg
    = GotImage (Result Http.Error (Maybe Image))

getImage : Cmd Msg
getImage =
    Http.get
        { url = "/image.png"
        , expect = Http.expectBytes GotImage Image.decode
        }

Encoding

toPng : Image -> Bytes

Portable Network Graphics (PNG) is a raster-graphics file-format that supports lossless data compression. PNG was developed as an improved, non-patented replacement for Graphics Interchange Format (GIF).

PNG supports palette-based images (with palettes of 24-bit RGB or 32-bit RGBA colors), grayscale images (with or without alpha channel for transparency), and full-color non-palette-based RGB images (with or without alpha channel).

toBmp : Image -> Bytes

The BMP file format, also known as bitmap image file or device independent bitmap (DIB) file format or simply a bitmap, is a raster graphics image file format used to store bitmap digital images, independently of the display device (such as a graphics adapter), especially on Microsoft Windows and OS/2 operating systems.

Note: Using BMP 32bit is discouraged due to lack of proper support across browsers, so image will be 24bit (no alpha channel)

toGif : Image -> Bytes

The Graphics Interchange Format (GIF)

Palette based image with support of animation (not implemented), Transparency (totally transparent color - use 0x00)

toPngUrl : Image -> String

Create base64-url that can be used directly as img source (img [ src <| toPngUrl myImage ])

toBmpUrl : Image -> String

Create base64-url that can be used directly as img source (img [ src <| toBmpUrl myImage ])

toGifUrl : Image -> String

Create base64-url that can be used directly as img source (img [ src <| toGifUrl myImage ])

Construct

fromList : Width -> List Pixel -> Image

Create Image of List Int where each Pixel is Int as 0xRRGGBBAA

fromList2d : List (List Pixel) -> Image

Create Image of List (List Int) where each Pixel is Int as 0xRRGGBBAA

fromArray : Width -> Array Pixel -> Image

Create Image of Array Int where each Pixel is Int as 0xRRGGBBAA

fromArray2d : Array (Array Pixel) -> Image

Create Image of Array (Array Pixel) where each Pixel is Int as 0xRRGGBBAA

Destruct

toList : Image -> List Pixel

Take Image of and converts it to List Pixel where each Pixel is Int as 0xRRGGBBAA

toList2d : Image -> List (List Pixel)

Take Image of and converts it to matrix List (List Pixel) where each Pixel is Int as 0xRRGGBBAA

toArray : Image -> Array Pixel

Take Image of and converts it to Array Pixel where each Pixel is Int as 0xRRGGBBAA

toArray2d : Image -> Array (Array Pixel)

Take Image of and converts it to matrix Array (Array Pixel) where each Pixel is Int as 0xRRGGBBAA

Meta Data

dimensions : Image -> { width : Basics.Int, height : Basics.Int }

Get width and height of Image

Helper Types


type alias Pixel =
Basics.Int

Color encoded as 0xRRGGBBAA


type alias Width =
Basics.Int


type alias Height =
Basics.Int