• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript sharp.default函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript sharp.queue类代码示例发布时间:2022-05-25
下一篇:
TypeScript sharp.concurrency函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap