We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
怎么给图片添加圆角
现在用的这个方法可以把图片切成圆形 jimp.circle();
但是这个只能把图片切成圆形
有方法可以给图片上下左右添加圆角吗
The text was updated successfully, but these errors were encountered:
There currently isn't an option to add border radius to a square. You could probably implement this as a plugin.
Sorry, something went wrong.
// 设置圆角的半径 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
No branches or pull requests
怎么给图片添加圆角
现在用的这个方法可以把图片切成圆形
jimp.circle();
但是这个只能把图片切成圆形
有方法可以给图片上下左右添加圆角吗
The text was updated successfully, but these errors were encountered: