当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript sharp.default函数代码示例

本文整理汇总了TypeScript中sharp.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了default函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: callbackRuntime

export default callbackRuntime(async (event: APIGatewayEvent) => {
  // NOTE currently needed for backward compatibility
  if (event.path.split('/')[1] !== 'v1') {
    try {
      // log projectId of projects using the old API version
      const client = new GraphQLClient(process.env['GRAPHCOOL_ENDPOINT']!, {
        headers: {
          Authorization: `Bearer ${process.env['GRAPHCOOL_PAT']}`,
        },
      })

      await client.request(`mutation {
        createApiUser(projectId: "${event.path.split('/')[1]}") { id }
      }`)
    } catch (e) {
      if (e.response.errors[0].code !== 3010) {
        throw e
      }
    }

    return {
      statusCode: 301,
      body: '',
      headers: {
        Location: `https://images.graph.cool/v1${event.path}`,
      },
    }
  }

  const [paramsErr, params] = parseParams(event.path)

  if (paramsErr) {
    return {
      statusCode: 400,
      body: paramsErr.toString(),
    }
  }

  const { projectId, fileSecret, crop, resize } = params!

  const options = {
    Bucket: process.env['BUCKET_NAME']!,
    Key: `${projectId}/${fileSecret}`,
  }

  const {
    ContentLength,
    ContentType,
    ContentDisposition,
  } = await s3.headObject(options).promise()

  if (ContentLength! > 25 * 1024 * 1024) {
    return {
      statusCode: 400,
      body: 'File too big',
    }
  }

  if (!ContentType!.includes('image')) {
    return {
      statusCode: 400,
      body: 'File not an image',
    }
  }

  // return original for gifs, svgs or no params
  if (
    ContentType === 'image/gif' ||
    ContentType === 'image/svg+xml' ||
    (resize === undefined && crop === undefined)
  ) {
    const obj = await s3.getObject(options).promise()
    const body = (obj.Body as Buffer).toString('base64')
    return base64Response(body, ContentType!, ContentDisposition!)
  }

  const s3Resp = await s3.getObject(options).promise()
  const stream = sharp(s3Resp.Body)

  try {
    const config = getConfig({ resize, crop })

    stream.limitInputPixels(false)

    if (config.crop) {
      stream.extract({
        left: config.crop.x,
        top: config.crop.y,
        width: config.crop.width,
        height: config.crop.height,
      })
    }

    if (config.resize) {
      stream.rotate()
      stream.resize(config.resize.width, config.resize.height)

      if (config.resize.force) {
        stream.ignoreAspectRatio()
      } else {
//.........这里部分代码省略.........
开发者ID:morristech,项目名称:serverless-image-proxy,代码行数:101,代码来源:handler.ts

示例2: generate

  public async generate(id: string, variant: string): Promise<SharpInstance> {
    const parts = this.getParts(id, variant)
    if (!parts.length) {
      throw new Error(`variant '${variant}'does not contain any parts`)
    }
    const { width, height } = await sharp(parts[0]).metadata()

    const options = {
      raw: {
        width: width!,
        height: height!,
        channels: 4
      }
    }
    const overlays = parts.map((part) =>
      sharp(part)
        .raw()
        .toBuffer()
    )

    let composite = overlays.shift()!
    for (const overlay of overlays) {
      const [compoisteData, overlayData] = await Promise.all([
        composite,
        overlay
      ])
      composite = sharp(compoisteData, options)
        .overlayWith(overlayData, options)
        .raw()
        .toBuffer()
    }
    return sharp(await composite, options)
  }
开发者ID:arusanov,项目名称:avatar-generator,代码行数:33,代码来源:index.ts

示例3: sharp

 setPhoto(user: User, file: Buffer, fileName: string): Promise<User> {
     log('setPhoto(); fileName=%o', fileName);
     const newFileName = `${uuid.v4()}${path.extname(fileName)}`;
     const dirName = 'user-photos';
     const outputFilePath = path.join(this.staticDirPath, dirName, newFileName);
     return sharp(file).resize(128, 128).max().toFile(outputFilePath)
         .then(() => {
             user.photoUrl = `${this.staticUrl}/${dirName}/${newFileName}`;
             return this.userService.save(user);
         });
 }
开发者ID:AndreyMalykhin,项目名称:DotaFanWarsBack,代码行数:11,代码来源:user-commander.ts

示例4: resizeImage

async function resizeImage(buffer) {
  const image = sharp(buffer);

  const { width } = await image.metadata();

  if (width <= MAX_WIDTH) {
    return buffer;
  }

  const resizedBuffer = await image.resize(MAX_WIDTH)
    .toBuffer();

  return resizedBuffer;
}
开发者ID:skatpgusskat,项目名称:redchat,代码行数:14,代码来源:encodeImage.ts

示例5: testThumbnailLib

 static async testThumbnailLib(processingLibrary: ThumbnailProcessingLib) {
   switch (processingLibrary) {
     case ThumbnailProcessingLib.sharp:
       const sharp = require('sharp');
       sharp();
       break;
     case  ThumbnailProcessingLib.gm:
       const gm = require('gm');
       await new Promise((resolve, reject) => {
         gm(ProjectPath.FrontendFolder + '/assets/icon.png').size((err: Error) => {
           if (err) {
             return reject(err.toString());
           }
           return resolve();
         });
       });
       break;
   }
 }
开发者ID:bpatrik,项目名称:PiGallery2,代码行数:19,代码来源:ConfigDiagnostics.ts

示例6: sharp

                return libraw.extract(photo.master, fileNamePath)
                    .then(output => {
                        model.set('master', output)
                        return output
                    })
            })
            .catch(err => {
                console.error('ERR', err)
            }))
    }
}, {
    updateImage(data) {
        let filename = [ data[1], data[2], data[3] ].join('-')
        let thumbPathName = `${config.thumbnailPath}/${filename}.jpg`

        return sharp(data.input)
            .resize(250, 250)
            .max()
            .toFile(thumbPathName)
            .then(() => Version.where({ photo_id: data[2], version: data[3] })
                    .fetch()
            )
            .then(version => {
                if (version) {
                    return version.save(
                        { output: data.input, thumbnail: thumbPathName },
                        { method: 'update' }
                    )
                }
    
                throw new Error('not-found')
开发者ID:m0g,项目名称:ansel,代码行数:31,代码来源:Version.ts

示例7: sharp

 .map(async (i: string) => sharp(sourcePath)
   .resize(sizes[i].width, sizes[i].height)
   .resize({ fit: "outside" })),
开发者ID:Blanket-Warriors,项目名称:Blog-O-Matic,代码行数:3,代码来源:createImageOutput.ts

示例8: sharp

 const overlays = parts.map((part) =>
   sharp(part)
     .raw()
     .toBuffer()
开发者ID:arusanov,项目名称:avatar-generator,代码行数:4,代码来源:index.ts

示例9: sharp

export const combine = (face: Face) =>
  sharp(face.eyes)
    .composite([{ input: face.mouth }, { input: face.nose }])
    .flatten({ background: face.color });
开发者ID:adorableio,项目名称:avatars-api,代码行数:4,代码来源:imaging.ts


注:本文中的sharp.default函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。