Comments (2)
There currently isn't an option to add border radius to a square. You could probably implement this as a plugin.
from jimp.
// 设置圆角的半径
const radius = 100;
// 计算圆角的半径
const radiusSquared = radius ** 2;
// 计算角的距离
const c1 = radius - 0.5;
const c2 = image.bitmap.width - radius - 1 + 0.5;
const c3 = image.bitmap.height - radius - 1 + 0.5;
// 循环处理每个像素
image.scan(0, 0, image.bitmap.width, image.bitmap.height, (x, y, idx) => {
// 计算当前像素到四个角的距离的平方
const distanceSquared = (x < radius ? c1 - x : x >= c2 ? x - c2 : 0) ** 2 + (y < radius ? c1 - y : y >= c3 ? y - c3 : 0) ** 2;
// 判断是否在圆角范围内,并根据对称性进行处理
if (distanceSquared > radiusSquared) {
image.bitmap.data[idx + 3] = 0; // 设置透明度为0,即完全透明
}
});
初始图片要大不然有锯齿严重,然后再resize
from jimp.
Related Issues (20)
- unrecognised content at end of stream
- Suggest adding Otsu's threshold algorithm
- No matter what, "Mime must be a string"
- Error reading arraybuffer in production environment HOT 1
- Share some examples of how to use it.(Multi page tiff from multiple images)
- @jimp/png won't work with @jimp/custom
- .brightness() method does not affect brightness
- Upgrade dependancy version of xml2js HOT 1
- Save to specific width and height in inches HOT 1
- Jimp.decoders is undefined in browser with webpack and typescript
- ERR_PNPM_NO_MATCHING_VERSION No matching version found for @jimp/plugin-scale@^0.22.12
- zlib_bindings problem when used in Vite with Typescript
- Do anyone can run jimp in latest reactjs project? HOT 1
- Unable to get it working in a Vue project. HOT 3
- [BUG] Error when using ES Modules with Jimp HOT 6
- Cannot load fonts in Web Worker
- Japanese characters not able to write and render image
- Unable to install jimp library through npm bcz of vulnerabilities checks HOT 2
- Update phin version HOT 8
- Reading base64 image from a Buffer is slow HOT 1
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.