stephenmoloney / fastimage

Find the type or size of an image

Home Page:https://hex.pm/packages/fastimage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hex Version Hex docs License Build Status Code coverage status Hex.pm

Fastimage

Description

Fastimage finds the dimensions/size or file type of a remote or local image file given the file path or url respectively. It streams the smallest amount of data necessary to ascertain the file size. This aspect is useful when getting the file size for very large images.

Features

  • Supports bmp, jpeg, png, webp and gif files
  • Supports local files by using the file path of the image
  • Supports blobs/objects by using the binary of the image
  • Supports remote files by using the url of the image
  • Follows redirects for a given url
  • Fastimage.info/1 yields the image info as a struct %Fastimage{}
  • Fastimage.size/1 yields the image size as a struct %Fastimage.Dimensions{width: _w, height: _h}
  • Fastimage.type/1 yields the image type as an atom :bmp, :jpeg, :gif, :webp or :png

Examples

Fastimage.info("https://raw.githubusercontent.com/stephenmoloney/fastimage/master/priv/test.jpg")
# => {:ok,
#      %Fastimage{
#        dimensions: %Fastimage.Dimensions{height: 142, width: 283},
#        image_type: :jpeg,
#        source: "https://raw.githubusercontent.com/stephenmoloney/fastimage/master/priv/test.jpg",
#        source_type: :url
#      }}

Fastimage.type("https://raw.githubusercontent.com/stephenmoloney/fastimage/master/priv/test.jpg")
# => {:ok, :jpeg}

Fastimage.size("https://raw.githubusercontent.com/stephenmoloney/fastimage/master/priv/test.jpg")
# => {:ok, %Fastimage.Dimensions{height: 142, width: 283}}

See docs for further examples

Installation

Add fastimage to your list of dependencies in mix.exs:

def deps do
  [
    {:fastimage, "~> 1.0.0-rc4"}
  ]
end

Tests

mix test

Benchmarks

mix bench

Credit/Acknowledgements

Licence

MIT Licence

About

Find the type or size of an image

https://hex.pm/packages/fastimage

License:MIT License


Languages

Language:Elixir 100.0%