Coder Social home page Coder Social logo

eim's Introduction

eim - Erlang ImageMagick Interface (for the web)

Provides nif helpers around MagickWand to resize, crop, and rotate images. This is the initial goal of the eim project due to these being the primary functions needed for web based services that require image uploading and basic manipulation functionality.

Due to the nature of NIFs if they crash the whole node goes down, which means you'd need to monitor/handle said crashes.

Examples

A photo hosting service which primarily deals with photographs of people may create these derivations of uploaded images:

1> {ok, Image} = eim:load(Binary).
2> %% make derivations here
   ...

Create a thumbnail of the top portion of the image and scale it to a box of 50x50 pixels - similar to default Facebook newsfeed profile pictures

DerivedBinary = eim:derive(Image, png, {box, 50, 50, center, top})

Resize the image to width 180 and maintain aspect ratio on the height and then make sure the height doesn't exceed 350, otherwise crop the bottom out so that it is exactly 350 height. Will result in an image with width 180 and a height of =< 350 - similar to Facebook style pictures on the left of profile pages

DerivedBinary = eim:derive(Image, png, [{scale, width, 180}, {max, height, 350, top}])

User defined cropping the image to a specific region - similar to the result of Facebook profile image thumbnail editing

DerivedBinary = eim:derive(Image, png, [{crop, 300, 300, 45, 130}, {scale, height, 50}])

Derivation Reference/API

Format can be one of the atoms jpg, gif, or png. You'll need imagemagick installed and configured with the other libraries necessary to read and write these formats.

crop a region

{crop, Width, Height, X, Y}

scale by width and maintain aspect ratio on height

{scale, width, Width}

scale by height and maintain aspect ratio on width

{scale, height, Height}

crop the image if it exceeds these limits float crop center

{max, width, Width} -> {max, width, Width, left}
{max, height, Height} -> {max, height, Height, top}

crop the image if it exceeds these limits and float the crop ** variable floating on max not currently supported **

{max, width, Width, FloatX}
{max, height, Height, FloatY}

crop to 350 if the original Height > 350 and float the crop in the top which is normally where someone's head is in a photograph

{max, height, 350, top}

fit inside this box by cropping out some of the image so it results in
am image exactly Width, Height in dimensions

{box, Width, Height} -> {crop_box, Width, Height, center, center}

same as above but with variable FloatX and FloatY

{box, Width, Height, FloatX, FloatY}

rotate 90 degress once, twice, or three times - 90, 180, or 270 degress

{rotate, 1}
{rotate, 2}
{rotate, 3}

fit inside a box of this size but maintain the aspect ratio results in either

% NewWidth =:= Width and NewHeight =< Height
% or NewHeight =:= Height and NewWidth =< Width
{fit, Width, Height}

eim's People

Contributors

mclap avatar mokele avatar

Watchers

 avatar

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.