adrsch / slider-captcha

User-friendly puzzle slider captcha for React and Express
MIT License
68 stars 38 forks source link

Latest version of sharp breaks slider puzzle piece #12

Open stevenmunro opened 3 years ago

stevenmunro commented 3 years ago

Great little plugin, loving it.

This package uses "sharp": "^0.25.4",

If I upgrade sharp to the latest version, the slider png returned from the create function is completely transparent. I haven't been able to pinpoint where in the composition process how this is happening. My knowledge of sharp is limited at this stage.

If anyone knows what the (I would imagine.. "small") fix would be, please share.

badboy-tian commented 2 years ago

+1

badboy-tian commented 2 years ago

downgrade to "sharp": "0.27.0",

bung87 commented 2 years ago

same as "sharp": "^0.29.3", and "sharp": "^0.30.4",

bung87 commented 2 years ago

found composite and extract must seperate to two steps

  const ins = sharp(image)
  .resize({ width: sizes.WIDTH, height: sizes.HEIGHT })
  return ins
      .composite([
        {
          input: overlay,
          blend: 'over',
          top: location.top,
          left: location.left,
        },
      ])
      .png()
      .toBuffer()
      .then(async (background) => {
        const composed = await ins
          .composite([
            {
              input: mask,
              blend: 'dest-in',
              top: location.top,
              left: location.left,
            },
            {
              input: outline,
              blend: 'over',
              top: location.top,
              left: location.left,
            },
          ]).toBuffer()
        return  sharp(composed).extract({
            left: location.left,
            top: 0,
            width: sizes.PUZZLE,
            height: sizes.HEIGHT,
          })
          .png()
          .toBuffer()
          .then((slider) => {
            return {
              data: {
                background,
                slider,
              },
              solution: location.left,
            };
          });
      });
badboy-tian commented 7 months ago

@bung87 the slider png returned from the create function is completely transparent use 0.33.3