sharp icon indicating copy to clipboard operation
sharp copied to clipboard

affine operation does not expand output area to include offsets

Open harumazzz opened this issue 3 years ago • 4 comments

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

harumazzz avatar Apr 16 '23 18:04 harumazzz

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

lovell avatar Apr 17 '23 07:04 lovell

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

harumazzz avatar Apr 17 '23 09:04 harumazzz

I have the same issue as this

hiepseafairy avatar Apr 18 '23 10:04 hiepseafairy

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

lovell avatar Apr 20 '23 15:04 lovell