Coder Social home page Coder Social logo

pixels's Introduction

Pixels

Elixir CI Hex pm

Elixir NIF to read and write image data from/to PNG and JPEG files.

For PNG images, it uses the lodepng C library; for JPEG images, it uses the ujpeg C library.

Progressive or lossless JPEG files, as well as JPEG encoding are not supported by the underlying uJpeg.

Getting Pixel data

Pixels.read and Pixels.read_file allow you to decode a PNG / JPEG file into a %Pixels{} struct. The data component of this struct contains the RGBA data of the image, in row order. To get an individual pixel's value, you can calculate an offset into this data based on the x/y coordinate. For example:

{:ok, pixels} = Pixels.read_file("test.png")

# the pixel value you want to get:
x = 10
y = 3

# calculate offset into `pixels.data`
offset = (y * pixels.width + x) * 4

# binary-pattern-match the pixel value in the data:
<<_::binary-size(offset), r, g, b, alpha, _::binary>> = pixels.data

I need feature X!

Pull requests welcome! For a more feature-complete library you could also use image, however its license is LGPL so a bit more restrictive than the MIT license of Pixels.

Installation

If available in Hex, the package can be installed by adding pixels to your list of dependencies in mix.exs:

def deps do
  [
    {:pixels, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/pixels.

pixels's People

Contributors

arjan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pixels's Issues

$CROSSCOMPILE Issue on MacOS

Hey @arjan, I've got a question that hopefully will be a quick fix for you. I'm on MacOS and trying to compile an Elixir project using this package but I'm getting an issue with the makefile.

Makefile:11: *** PNG only works on Linux. Crosscompiling is possible if $CROSSCOMPILE is set.. Stop.

I was having trouble trying to figure out where $CROSSCOMPILE should be set. The configuration does seem to work as is on Windows with WSL. I'm assuming I need to set something in the .zshrc file but I'm not 100% sure. Hoping you can help out. Thanks!

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.