How to use the pica function in pica

To help you get started, we’ve selected a few pica examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FreemapSlovakia / freemap-v3-react / src / hooks / pictureDropHandlerHook.ts View on Github external
number,
      number,
      number,
      number,
    ][] = [
      [1, 0, 0, 1, 0, 0],
      [-1, 0, 0, 1, width, 0],
      [-1, 0, 0, -1, width, height],
      [1, 0, 0, -1, 0, height],
      [0, 1, 1, 0, 0, 0],
      [0, 1, -1, 0, height, 0],
      [0, -1, -1, 0, height, width],
      [0, -1, 1, 0, 0, width],
    ];

    pica()
      .resize(img, canvas)
      .then(() => {
        let canvas2: HTMLCanvasElement;
        if (o === 1) {
          canvas2 = canvas;
        } else {
          canvas2 = document.createElement('canvas');
          const ctx = canvas2.getContext('2d');
          if (!ctx) {
            throw new Error('context is null');
          }
          canvas2.width = o > 4 ? height : width;
          canvas2.height = o > 4 ? width : height;
          ctx.transform(...transformations[o - 1]);
          ctx.drawImage(canvas, 0, 0);
        }
github deltaepsilon / firebase-ssr-starter / utilities / storage / resize-image.js View on Github external
export default async function resizeImage(src, el, targetDimensions) {
  const pica = Pica();
  const from = document.createElement('canvas');
  const fromContext = from.getContext('2d');
  const to = document.createElement('canvas');

  const fromImage = new Image();
  fromImage.src = src;

  const stats = await getImageStats(fromImage);
  const newDimensions = getNewDimensions(stats, targetDimensions);

  from.width = stats.width;
  from.height = stats.height;
  to.height = newDimensions.height;
  to.width = newDimensions.width;

  fromContext.drawImage(fromImage, 0, 0);

pica

High quality image resize in browser.

MIT
Latest version published 2 years ago

Package Health Score

56 / 100
Full package analysis