Options
All
  • Public
  • Public/Protected
  • All
Menu

Module data/getImgToBase64

Index

Enumerations

Interfaces

Functions

Functions

Const getImgToBase64

0.0.35 provide
  • getImgToBase64(url: string, options?: ImgOptions): Promise<string>
  • 将图片的 url 转为 base64 格式

    remarks

    如果img对应的图片是APNG形式的(或者是后缀为png的动图),请指定类型为APNG或者不传函数的第二个参数

    example

    not options

    import { data } from 'onex-utils';
    data.getImgToBase64('https://gw.alicdn.com/imgextra/i3/O1CN01lsi6bB1O7PK4ba7GK_!!6000000001658-2-tps-90-70.png').then(base64 => {
    console.log('生成的base64位:', base64)
    })
    
    example

    appoint type

    import { data } from 'onex-utils';
    
    const { ImgType, getImgToBase64 } = data;
    
    getImgToBase64('https://gw.alicdn.com/imgextra/i3/O1CN01lsi6bB1O7PK4ba7GK_!!6000000001658-2-tps-90-70.png', { type: ImgType.PNG }).then(base64 => {
    console.log('生成的base64位:', base64)
    })
    
    example

    针对APNG动图

    import { data } from 'onex-utils';
    data.getImgToBase64('https://ossgw.alicdn.com/ace-tiny-resources/platform/pre/capture/d016edec-5043-4b49-b34c-0ecf4f6ba3c6/2021-01-21/628408979991_n88QCNZhztEQOHStkgBdeWN4_frame.apng')
    .then(base64 => {
       console.log('生成的base64为:', base64)
    })
    

    Parameters

    • url: string

      需要转化的url链接

    • Optional options: ImgOptions

      非必选,针对生成base64进行配置,具体配置 ImgOptions

    Returns Promise<string>

    • data base64