npm包florest使用教程

阅读时长 5 分钟读完

背景

在进行前端开发的时候,很多时候都需要用到图片;而随着互联网数据大规模的发展,图片处理也变得越来越复杂。florest是一款npm包能够与在线图片处理 API 集成,实现图像处理的目的。

安装

安装florest,打开终端,输入以下命令:

快速上手

智能裁剪

-- -------------------- ---- -------
------ - --------- - ---- ----------

----- -------- ------ -
  ----- ------- - ----- ----------------
    ------- ---- -----
    ---------- ---- --------
    ---- --------------------------------
    ------ ----
    ------- ----
    ------ ----
  ---

  ---------------------
-

-------
展开代码

智能变黑白

-- -------------------- ---- -------
------ - --------- - ---- ----------

----- -------- ------ -
  ----- ------- - ----- ----------------
    ------- ---- -----
    ---------- ---- --------
    ---- -------------------------------
  ---

  ---------------------
-

-------
展开代码

图片压缩

-- -------------------- ---- -------
------ - ------------- - ---- ----------

----- -------- ---------- -
  ----- ------- - ----- ------------------------
    ------- ---- -----
    ---------- ---- --------
    ---- --------------------------------
    -------- --
  ---

  ---------------------
-

----------
展开代码

API

SmartCrop.crop()

智能裁剪

参数

  • apiKey string:API Key
  • apiSecret string:API Secret
  • url string:图片 URL
  • width number:目标宽度
  • height number:目标高度
  • scale boolean:是否根据目标宽度和高度等比例缩放

返回值

-- -------------------- ---- -------
-
  ----- ----
  ----- -
    ---- ---
    ------ ---
    ------- ---
    ---- ---
    ----- ---
    ------ ---
    ------- ---
    ------ ---
    ----- ---
    -------- ---
    ------- ---
    ---------- ---
    ------- --
  --
  -------- --------------
-
展开代码

SmartGray.gray()

智能变黑白

参数

  • apiKey string:API Key
  • apiSecret string:API Secret
  • url string:图片 URL

返回值

SmartCompress.compress()

图片压缩

参数

  • apiKey string:API Key
  • apiSecret string:API Secret
  • url string:图片 URL
  • quality number:图片质量(建议 60 ~ 80)

返回值

总结

florest 是一款方便实用的 npm 包,可以与在线图片处理 API 集成,可以实现一些很有用的图片处理方法,希望大家在学习使用过程中能够有所收获。

来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/600554df81e8991b448d2138

纠错
反馈

纠错反馈