Giter VIP home page Giter VIP logo

imago's Introduction

2024 Notice

Hey :-) . If you stumble upon that, you should use Vix (https://hex.pm/packages/vix) or Image (https://hex.pm/packages/image) now.

Imago

Bindings (for my usage) to image-rs/image. Mainly because I didn't find any Elixir/Erlang library to iterate over pixels of compressed formats like Jpeg. I'll need to at least open/process a bit/save images from rust.

At the time of this writing, it supports only those things :

  • getting a (w: u8, h: u8, pixels: Vec<u8>) of r/g/b/a, rgb, or rgba pixels
  • getting a Vec<u8> that represents a luminance fingerprint.
  • filters: threshold(path, threshold), dither_bayer(path, threshold)
  • saving something as a PGM image (mainly to check validity.)
iex> Imago.read_pixels("/path/to/image.jpg|png|gif|ico|bmp|tiff") # Image formats are those of image-rs/image
{:ok,
 {1200, 1500, [131, 140, 157, 255, 130, 139, 156, 255, 131, 138, 156, 255, 131, 138, 156,
  255, 134, 139, 158, 255, 134, 139, 158, 255, 136, 139, 158, 255, 135, 138,
  157, 255, 135, 136, 156, 255, 135, 136, 156, 255, 136, 137, 157, 255, 136,
  137, 157, 255, ...]}}

iex(1)> Imago.get_fingerprint_4x4("/path/to/image.jpg")
{:ok,
 [132, 138, 103, 110, 138, 119, 112, 125, 127, 121, 120, 133, 134, 125, 131,
  139]}
  
iex(1)> Imago.get_fingerprint_8x8("/path/to/image.jpg")
{:ok,
 [113, 144, 157, 115, 100, 102, 106, 109, 130, 141, 169, 112, 103, 107, 113,
  114, 142, 143, 138, 108, 108, 112, 120, 123, 128, 139, 120, 112, 112, 115,
  129, 126, 130, 126, 124, 117, 116, 120, 130, 133, 132, 122, 123, 119, 120,
  124, 129, 137, ...]}

iex> Imago.read_pixels("/this/one/does/not/exist")
:error

iex> Imago.read_pixels("/this/one/is_a_text_file.txt")
:error

Luminance fingerprinting is done that way :

Luminance fingerprinting

Available utilities:

iex> Imago.read_pixels("x.jpg")
  {:ok, [r, g, b, a, r, g, b, a]}  

iex> Imago.read_pixels_rgba("x.jpg")
  {:ok, [r, g, b, a, r, g, b, a]}     

iex> Imago.read_pixels_rgb("x.jpg")
  {:ok, [r, g, b, r, g, b]}     

iex> Imago.read_pixels_red("x.jpg")
  {:ok, [r, r, r]}  

iex> Imago.read_pixels_green("x.jpg")
  {:ok, [g, g, g]}  

iex> Imago.read_pixels_blue("x.jpg")
  {:ok, [b, b, b, b]}   

iex> Imago.read_pixels_alpha("x.jpg")
  {:ok, [a, a, a, a]}

iex(1)> Imago.get_fingerprint_4x4("/path/to/image.jpg")
{:ok,
 [l, l, l, l,
  l, l, l, l,
  l, l, l, l,
  l, l, l, l]} # where l = luminance
  
iex(1)> Imago.get_fingerprint_8x8("/path/to/image.jpg")
{:ok,
 [l, l, l, l, l, l, l, l,
  l, l, l, l, l, l, l, l,
  l, l, l, l, l, l, l, l,
  l, l, l, l, l, l, l, l,
  l, l, l, l, l, l, l, l,
  l, l, l, l, l, l, l, l,
  l, l, l, l, l, l, l, l,
  l, l, l, l, l, l, l, l
 ]} # where l = luminance
 
iex(1)> {:ok, r} = Imago.dither_bayer('moon.jpg', 50)
        {:ok, {width, height, [pixels]}}
iex(1)> Imago.save_pgm(r)
        :ok

imago's People

Contributors

dependabot[bot] avatar lucassifoni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

imago's Issues

API

All the methods should fill an internal Imago operation descriptor struct, then only be executed by the Rust side by a final "run" operation. Without this, continuing to add methods will be a mess with each method having its own file open/etc logic.

Example :

    "test.jpg"
|> Imago.open # %Imago.Actions{ list: [{:open, ["test.jpg"]}] }
|> Imago.resize_fixed(300, 300) # %Imago.Actions{ list: [{:open, "test.jpg"}, {:resize, [300, 300]} ]}
|> Imago.dither_bayer(65) # %Imago.Actions{ list: [{:open, "test.jpg"}, {:resize, [300, 300]}, {:dither_bayer, [65]} ]}
|> Imago.save("out.jpg") # %Imago.Actions{ list: [{:open, "test.jpg"}, {:resize, [300, 300]}, {:dither_bayer, [65]}, {:save, ["out.jpg"]} ]}
|> Imago.run # Things are actually done, returns {width, height, [pixels]} as it did before

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.