lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
29.22k stars 1.29k forks source link

affine operation does not expand output area to include offsets #3632

Open Haruma-VN opened 1 year ago

Haruma-VN commented 1 year ago

Feature request

What are you trying to achieve?

I want to apply trasform like matrix transfrom in css. EX: matrix(1, 0, 0, 1, 78.8, 22.2). I could use affine for scale and skew in matrix .affine([1, 0], [0, 1]), but when i tried to apply translation by using composite. It throwed error top, left must be int. Do you have anyway that i can use float in composite or special function which can apply matrix

lovell commented 1 year ago

The affine() operation is for applying matrix transformations and accepts floats. Did you see the idx etc. properties for translation offsets?

https://sharp.pixelplumbing.com/api-operation#affine

Haruma-VN commented 1 year ago

I want to composite one image to another image created by sharp and using a matrix, using affine and adding odx and ody to the option. However, I'm facing an issue where the image is being cropped if odx exceeds the size of the image being affine. Here is my code:

// matrix(1, 0.5, 0, 1, 32.3, 54.5)
sharp("input.png").affine([1, 0 , 0.5, 1], { background: "#00000000", odx: 32.3, ody: 44.5}).toBuffer().then(image_1 => {
  sharp({
    create: {
      width: 300,
      height: 200,
      channels: 4,
      background: { r: 0, g: 0, b: 0, alpha: 0 }
    }
  })
  .png().composite([{input: image_1, top: 0, left: 0}]).toFile('image_1.png');
});

received_973100550714564.png

received_753806882987535.png

hiepseafairy commented 1 year ago

I have the same issue as this

lovell commented 1 year ago

I've created https://github.com/libvips/libvips/discussions/3454 to discuss this upstream in libvips.