背景
在进行前端开发的时候,很多时候都需要用到图片;而随着互联网数据大规模的发展,图片处理也变得越来越复杂。florest是一款npm包能够与在线图片处理 API 集成,实现图像处理的目的。
安装
安装florest,打开终端,输入以下命令:
npm install florest
快速上手
智能裁剪
-- -------------------- ---- ------- ------ - --------- - ---- ---------- ----- -------- ------ - ----- ------- - ----- ---------------- ------- ---- ----- ---------- ---- -------- ---- -------------------------------- ------ ---- ------- ---- ------ ---- --- --------------------- - -------展开代码
智能变黑白
-- -------------------- ---- ------- ------ - --------- - ---- ---------- ----- -------- ------ - ----- ------- - ----- ---------------- ------- ---- ----- ---------- ---- -------- ---- ------------------------------- --- --------------------- - -------展开代码
图片压缩
-- -------------------- ---- ------- ------ - ------------- - ---- ---------- ----- -------- ---------- - ----- ------- - ----- ------------------------ ------- ---- ----- ---------- ---- -------- ---- -------------------------------- -------- -- --- --------------------- - ----------展开代码
API
SmartCrop.crop()
智能裁剪
SmartCrop.crop({ apiKey: '', apiSecret: '', url: '', width: '', height: '', scale: '' });
参数
apiKey
string:API KeyapiSecret
string:API Secreturl
string:图片 URLwidth
number:目标宽度height
number:目标高度scale
boolean:是否根据目标宽度和高度等比例缩放
返回值
-- -------------------- ---- ------- - ----- ---- ----- - ---- --- ------ --- ------- --- ---- --- ----- --- ------ --- ------- --- ------ --- ----- --- -------- --- ------- --- ---------- --- ------- -- -- -------- -------------- -展开代码
SmartGray.gray()
智能变黑白
SmartGray.gray({ apiKey: '', apiSecret: '', url: '' });
参数
apiKey
string:API KeyapiSecret
string:API Secreturl
string:图片 URL
返回值
{ code: 200, data: { url: '', base64: '' }, message: 'successfully' }
SmartCompress.compress()
图片压缩
SmartCompress.compress({ apiKey: '', apiSecret: '', url: '', quality: '' });
参数
apiKey
string:API KeyapiSecret
string:API Secreturl
string:图片 URLquality
number:图片质量(建议 60 ~ 80)
返回值
{ code: 200, data: { url: '', base64: '' }, message: 'successfully' }
总结
florest 是一款方便实用的 npm 包,可以与在线图片处理 API 集成,可以实现一些很有用的图片处理方法,希望大家在学习使用过程中能够有所收获。
来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/600554df81e8991b448d2138