Comments (6)
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!
from jimp.
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.
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.
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.
@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.
@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
from jimp.
Related Issues (20)
- Unable to install jimp library through npm bcz of vulnerabilities checks HOT 3
- Update phin version HOT 9
- Reading base64 image from a Buffer is slow HOT 2
- nvm sorry my bad
- problem with the file path when reading the file HOT 1
- autocrop cropEmpty: true HOT 1
- Can't find 'resize/ method anymore HOT 12
- How to migrate to v1? HOT 2
- `fromBuffer` doesn't work in ESM projects HOT 3
- [doc] The examples of the migration guide are erroneous HOT 1
- Cannot find module `@jimp/plugin-print/load-font`, when used in Jest test HOT 4
- Most methods disappeared in v1 HOT 1
- Best practice for "generic" Jimp instance type missing from docs? HOT 5
- TypeError: Jimp.read is not a function HOT 1
- `JimpInstance` type can't be used consistently when working with Jimp instances
- No any wasm-* plugin on Mac Arm64 [in browser usage]
- Use fetch to load fonts in load Font, but it fails in the node environment
- nvm
- Documentation is incorrect for getBuffer (example)
- Jimp.fromBitmap is not a function!? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jimp.