https://github.com/stephenmoloney/fastimage
Find the type or size of an image
https://github.com/stephenmoloney/fastimage
dimensions elixir elixir-lang fastimage image image-analysis
Last synced: 11 months ago
JSON representation
Find the type or size of an image
- Host: GitHub
- URL: https://github.com/stephenmoloney/fastimage
- Owner: stephenmoloney
- License: mit
- Created: 2016-08-09T15:39:21.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-05-06T14:27:02.000Z (over 3 years ago)
- Last Synced: 2025-02-27T12:15:39.138Z (11 months ago)
- Topics: dimensions, elixir, elixir-lang, fastimage, image, image-analysis
- Language: Elixir
- Homepage: https://hex.pm/packages/fastimage
- Size: 219 KB
- Stars: 33
- Watchers: 3
- Forks: 9
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
[](https://hex.pm/packages/fastimage) [](https://hexdocs.pm/fastimage) [](https://github.com/stephenmoloney/fastimage/blob/master/LICENSE.md) [](https://travis-ci.org/stephenmoloney/fastimage) [](https://coveralls.io/github/stephenmoloney/fastimage?branch=master)

# 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
```elixir
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](https://hex.pm/packages/fastimage) for further examples
## Installation
Add fastimage to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:fastimage, "~> 1.0.0-rc4"}
]
end
```
## Tests
```elixir
mix test
```
## Benchmarks
```elixir
mix bench
```
## Credit/Acknowledgements
- Based on [Ruby Fastimage](https://github.com/sdsykes/fastimage) by [Stephen Sykes](https://github.com/sdsykes)
- Influenced by a [PHP version of fastimage](https://github.com/tommoor/fastimage) by [Tom Moor](https://github.com/tommoor)
- Thanks to all [contributors](https://github.com/stephenmoloney/fastimage/graphs/contributors)
## Licence
[MIT Licence](LICENCE.md)