src/managers/image-generator.js
/**
   * Shears an image layer.
   * @private
   * @param   {DepreciatedJimp} img    the image to be sheared
   * @param   {Number}          offset the tangent offset in pixels
   */
Shears an image layer.
@private
@param   {DepreciatedJimp} img    the image to be sheared
@param   {Number}          offset the tangent offset in pixels
Shears an image layer . @private @param { DepreciatedJimp } img the image to be sheared @param { Number } offset the tangent offset in pixels
shear(img, offset) {
    const source = img.cloneQuiet();
    img.scanQuiet(0, 0, img.bitmap.width, img.bitmap.height,
      (x, y, idx) => {
        img.bitmap.data.writeUInt32BE(img._background, idx);
      });
    img.resize(img.getWidth(), img.getHeight() + Math.abs(offset));
    img.scanQuiet(0, 0, img.bitmap.width, img.bitmap.height,
      (x, y, idx) => {
        let displacement = 0;
        if (offset > 0) {
          displacement = x / source.getWidth() * offset;
        } else {
          displacement = (x - source.getWidth()) / source.getWidth() * offset;
        }
        const pixelOffset = displacement - Math.round(displacement);
        displacement = Math.round(displacement);
        const sourceY = y - displacement;
        let pixelRGBA = img._background;
        if (sourceY >= 0) {
          pixelRGBA = source.bitmap.data.readUInt32BE(source.getPixelIndex(x, sourceY));
        }
        const sourceBlendY = pixelOffset < 0 ? sourceY + 1 : sourceY - 1;
        let pixelToBlend = img._background;
        if (sourceBlendY >= 0) {
          const pixelToBlendIds = source.getPixelIndex(x, sourceBlendY);
          pixelToBlend = source.bitmap.data.readUInt32BE(pixelToBlendIds);
        }
        const pixelBlended = this.blendPixels(pixelRGBA, pixelToBlend, Math.abs(pixelOffset));
        img.bitmap.data.writeUInt32BE(pixelBlended, idx);
      });
    return img;
  }
shear ( img , offset ) { const source = img . cloneQuiet ( ) ; img . scanQuiet ( 0 , 0 , img . bitmap . width , img . bitmap . height , ( x , y , idx ) => { img . bitmap . data . writeUInt32BE ( img . _background , idx ) ; } ) ; img . resize ( img . getWidth ( ) , img . getHeight ( ) + Math . abs ( offset ) ) ; img . scanQuiet ( 0 , 0 , img . bitmap . width , img . bitmap . height , ( x , y , idx ) => { let displacement = 0 ; if ( offset > 0 ) { displacement = x / source . getWidth ( ) * offset ; } else { displacement = ( x - source . getWidth ( ) ) / source . getWidth ( ) * offset ; } const pixelOffset = displacement - Math . round ( displacement ) ; displacement = Math . round ( displacement ) ; const sourceY = y - displacement ; let pixelRGBA = img . _background ; if ( sourceY >= 0 ) { pixelRGBA = source . bitmap . data . readUInt32BE ( source . getPixelIndex ( x , sourceY ) ) ; } const sourceBlendY = pixelOffset < 0 ? sourceY + 1 : sourceY - 1 ; let pixelToBlend = img . _background ; if ( sourceBlendY >= 0 ) { const pixelToBlendIds = source . getPixelIndex ( x , sourceBlendY ) ; pixelToBlend = source . bitmap . data . readUInt32BE ( pixelToBlendIds ) ; } const pixelBlended = this . blendPixels ( pixelRGBA , pixelToBlend , Math . abs ( pixelOffset ) ) ; img . bitmap . data . writeUInt32BE ( pixelBlended , idx ) ; } ) ; return img ; }
Shears an image layer.
Shears an image layer .
// Resize to fit result