Giter Club home page Giter Club logo

Comments (6)

oliver-moran avatar oliver-moran commented on September 23, 2024 8

This is very easy using masks:

var p1 = Jimp.read("lenna.png");
var p2 = Jimp.read("mask.png");

Promise.all([p1, p2]).then(function(images){
    var lenna = images[0];
    var mask = images[1];
    lenna.mask(mask, 0, 0).write("lenna-circle.png");
});

And this is exactly the purpose I wrote Jimp for BTW. Best of luck!


lenna
mask
lenna-circle

from jimp.

haydenbleasel avatar haydenbleasel commented on September 23, 2024

Yep that was my fallback solution, problem is when you're programmatically generating images of different sizes, scaling a single size mask won't give the best quality, but no matter.

from jimp.

oliver-moran avatar oliver-moran commented on September 23, 2024

Is it that bad? Try creating just one "high resolution" icon then scaling and saving that:

var p1 = Jimp.read("lenna.png");
var p2 = Jimp.read("mask.png");

Promise.all([p1, p2]).then(function(images){
    var lenna = images[0];
    var mask = images[1];

    lenna.mask(mask, 0, 0).write("lenna-circle.png");

    var sizes = [256, 128, 64, 60, 48, 32, 30, 16];

    for (var i = 0; i < sizes.length; i++) {
        lenna.clone().resize(sizes[i], Jimp.AUTO)
        .write("lenna-circle" + i + ".png");
    }
});

from jimp.

haydenbleasel avatar haydenbleasel commented on September 23, 2024

It'll definitely work, just saying it won't be absolutely pixel-perfect, but I guess then again neither will the resized image so it's all good :)

from jimp.

spsiddarthan avatar spsiddarthan commented on September 23, 2024

@oliver-moran, @haydenbleasel : I was trying to do the exact same thing today. I just wanted to know if I understood the concept of mask correctly.

If I have an image with dimensions x*x and want to create the circular crop for it, I first have to generate the mask image on the fly. Is that correct?

from jimp.

devdemi avatar devdemi commented on September 23, 2024

@oliver-moran is there possibility to make transparent corners? I want to generate circular avatar and composite it with another image but that image has not white background
b7fc031739

from jimp.

Related Issues (20)

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.