Elxvips (elxvips v0.1.7)

View Source

Documentation for Elxvips.

Summary

Functions

Will save the ImageFile in avif(AV1) format to a specified path. Accepts quality and strip options. By default quality is set to 100

Sets the background of the image in case there is a transparent background. Accepts a empty list, or a list of length 2 or 3.

Will create an %ImageByte{} struct from bitstring or byte list. This struct will be used for further processing.

Will create an %ImageFile{} struct from path. This struct will be used for further processing.

Will create an %ImageFile{} struct from a pdf path. This struct will be used for further processing. Accepts the following options

Will create an %ImageByte{} struct from pdf bitstring or byte list. This struct will be used for further processing. Accepts the following options

Returns format of the specified image, works with a image path or bytes.

Returns dimensions of the specified image, works with a image path or bytes.

Will save the ImageFile in jpeg format to a specified path. Accepts quality and strip options. By default quality is set to 90 and strip to true.

Will save the ImageFile in png format to a specified path. Accepts quality, compression(0-9) and strip options. By default quality is set to 100, compression to 6, strip to true. Decreasing compression will speed up image saving.

Applies resize options to an %ImageFile{} or %ImageBytes{}, accepts :width, :height and :type (not implemented yet). If no width or height is specified dimensions are calculated from the input image. Empty resize( no :width and no :height) will produce an image with the dimensions as the original one.

Will save the ImageFile in SVG format to a specified path. Accepts no options. Highly discouraged to use this function, since it will embed the image in the svg file. In case an svg is used as input, it will just copy the file.

Will create a new %ImageBytes{} struct containing all the changes.

Will save the image to a path on disk and return a new %ImageFile{} from the new path.

Will save the ImageFile in webp format to a specified path. Accepts quality and strip options. By default quality is set to 100, and strip to true.

Functions

avif(image, opts \\ [])

Will save the ImageFile in avif(AV1) format to a specified path. Accepts quality and strip options. By default quality is set to 100

Examples

iex> import Elxvips
iex>
iex> from_file( "/path/input.jpg" )
iex> |> avif( quality: 72 )
iex  |> to_file( "/path/output.avif" )
{ :ok, %ImageFile{} }

background(image, opts \\ [])

Sets the background of the image in case there is a transparent background. Accepts a empty list, or a list of length 2 or 3.

Examples

iex> import Elxvips
iex>
iex> from_file( "test/input.png" )
iex  |> jpg()
iex> |> background( [ 255, 0, 0 ] ) # red background
iex  |> to_file( "test/output.jpg" )
{:ok, %ImageBytes{}}

check_opts(opts \\ [])

from_bytes(bytes)

Will create an %ImageByte{} struct from bitstring or byte list. This struct will be used for further processing.

Examples

iex> import Elxvips
iex>
iex> file = File.open!( "/path/input.png" )
iex> bytes = IO.binread( file, :all )
iex> from_bytes( bytes )
%ImageBytes{}

from_file(path)

Will create an %ImageFile{} struct from path. This struct will be used for further processing.

Examples

iex> import Elxvips
iex>
iex> from_file( "/path/input.png" )
%ImageFile{}

from_pdf(path, opts \\ [page: 0])

Will create an %ImageFile{} struct from a pdf path. This struct will be used for further processing. Accepts the following options:

  • :page - page number to extract from pdf, default is 0
  • :n - number of pages to extract from pdf, default is 1

Examples

iex> import Elxvips
iex>
iex> from_pdf( "/path/input.pdf", page: 0, n: 2 )
%ImageFile{}

from_pdf_bytes(bytes)

Will create an %ImageByte{} struct from pdf bitstring or byte list. This struct will be used for further processing. Accepts the following options:

  • :page - page number to extract from pdf, default is 0
  • :n - number of pages to extract from pdf, default is 1

Examples

iex> import Elxvips
iex>
iex> file = File.open!( "/path/input.pdf" )
iex> bytes = IO.binread( file, :all )
iex> from_pdf_bytes( bytes, page: 0, n: 2 )
%ImageBytes{}

from_pdf_bytes(bytes, opts)

get_image_format(arg1)

Returns format of the specified image, works with a image path or bytes.

Examples

iex> import Elxvips
iex>
iex> from_file( "test/input.png" )
iex> |> get_image_format()
{:ok, :png}

get_image_sizes(arg1)

Returns dimensions of the specified image, works with a image path or bytes.

Examples

iex> import Elxvips
iex>
iex> from_file( "test/input.png" )
iex> |> get_image_sizes()
{:ok, [640, 486]}

jpg(image, opts \\ [])

Will save the ImageFile in jpeg format to a specified path. Accepts quality and strip options. By default quality is set to 90 and strip to true.

Examples

iex> import Elxvips
iex>
iex> from_file( "/path/input.png" )
iex> |> jpg( strip: true, quality: 72 )
iex  |> to_file( "/path/output.jpg" )
{ :ok, %ImageFile{} }

png(image, opts \\ [])

Will save the ImageFile in png format to a specified path. Accepts quality, compression(0-9) and strip options. By default quality is set to 100, compression to 6, strip to true. Decreasing compression will speed up image saving.

Examples

iex> import Elxvips
iex>
iex> from_file( "/path/input.jpg" )
iex> |> png( strip: true, quality: 72 )
iex  |> to_file( "/path/output.png" )
{ :ok, %ImageFile{} }

resize(image_file, opts \\ [])

Applies resize options to an %ImageFile{} or %ImageBytes{}, accepts :width, :height and :type (not implemented yet). If no width or height is specified dimensions are calculated from the input image. Empty resize( no :width and no :height) will produce an image with the dimensions as the original one.

Examples

iex> import Elxvips
iex>
iex> from_file( "test/input.png" )
iex> |> resize( width: 300 )
iex  |> to_bytes()
{:ok, %ImageBytes{}}

set_concurrency(concurrency)

svg(image, opts \\ [])

Will save the ImageFile in SVG format to a specified path. Accepts no options. Highly discouraged to use this function, since it will embed the image in the svg file. In case an svg is used as input, it will just copy the file.

Examples

iex> import Elxvips
iex>
iex> from_file( "/path/input.jpg" )
iex> |> svg()
iex  |> to_file( "/path/output.svg" )
{ :ok, %ImageFile{} }

to_bytes(image)

Will create a new %ImageBytes{} struct containing all the changes.

Examples

iex> import Elxvips
iex>
iex> from_file( "test/input.png" )
iex> |> png()
iex> |> to_bytes()
{:ok, %ImageBytes{}}

to_file(image, path)

Will save the image to a path on disk and return a new %ImageFile{} from the new path.

Examples

iex> import Elxvips
iex>
iex> from_file( "test/input.png" )
iex> |> png()
iex> |> to_file( "test/outping.png" )
{:ok, %ImageBytes{}}

webp(image, opts \\ [])

Will save the ImageFile in webp format to a specified path. Accepts quality and strip options. By default quality is set to 100, and strip to true.

Examples

iex> import Elxvips
iex>
iex> from_file( "/path/input.jpg" )
iex> |> webp( strip: true, quality: 72 )
iex  |> to_file( "/path/output.webp" )
{ :ok, %ImageFile{} }