Giter Club home page Giter Club logo

Comments (2)

hipstersmoothie avatar hipstersmoothie commented on July 24, 2024

There currently isn't an option to add border radius to a square. You could probably implement this as a plugin.

from jimp.

tsoil avatar tsoil commented on July 24, 2024
  // 设置圆角的半径
  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)

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.