矢量图的用途,矢量图的特点及用途

首页 > 经验 > 作者:YD1662024-01-01 10:51:37

(图片来源:https://freecontent.manning.com/the-computer-vision-pipeline-part-2-input-images/)

「图像处理的本质实际上就是对这些像素矩阵进行计算。」 其实位图中的图像类型,除了二值图像和 RGB 图像之外,还有灰度图像、索引图像和 YUV 图像。这里我们不做过多介绍,感兴趣的小伙伴,请自行查阅相关资料。

二、图片处理库2.1 AlloyImage

基于 HTML 5 的专业级图像处理开源引擎。

https://github.com/AlloyTeam/AlloyImage

AlloyImage 基于 HTML5 技术的专业图像处理库,来自腾讯 AlloyTeam 团队。它拥有以下功能特性:

对于该库 AlloyTeam 团队建议的使用场景如下:

「使用示例」

//$AI或AlloyImage初始化一个AlloyImage对象 varps=$AI(img,600).save('jpg',0.6); //save将合成图片保存成base64格式字符串 varstring=AlloyImage(img).save('jpg',0.8); //savefile将合成图片下载到本地 img.onclick=function(){ AlloyImage(this).saveFile('处理后图像.jpg',0.8); }

「在线示例」

http://alloyteam.github.io/AlloyImage/

矢量图的用途,矢量图的特点及用途(5)

(图片来源:http://alloyteam.github.io/AlloyImage/)

2.2 blurify

blurify.js is a tiny(~2kb) library to blurred pictures, support graceful downgrade from css mode to canvasmode.

https://github.com/JustClear/blurify

blurify.js 是一个用于图片模糊,很小的 JavaScript 库(约 2 kb),并支持从 CSS 模式到 Canvas 模式的优雅降级。该插件支持三种模式:

「使用示例」

importblurifyfrom'blurify'; newblurify({ images:document.querySelectorAll('.blurify'), blur:6, mode:'css', }); //orinshorthand blurify(6,document.querySelectorAll('.blurify'));

「在线示例」

https://justclear.github.io/blurify/

矢量图的用途,矢量图的特点及用途(6)

(图片来源:https://justclear.github.io/blurify/)

看到这里是不是有些小伙伴觉得只是模糊处理而已,觉得不过瘾,能不能来点更酷的。嘿嘿,有求必应!阿宝哥立马来个 「“酷炫叼”」 地库 —— midori,该库用于为背景图创建动画,使用 three.js 编写并使用 WebGL。本来是想给个演示动图,无奈单个 Gif 文件太大,只能放个体验地址,感兴趣的小伙伴自行体验一下。

midori 示例地址:https://aeroheim.github.io/midori/

2.3 cropperjs

JavaScript image cropper.

https://github.com/fengyuanchen/cropperjs

Cropper.js 是一款非常强大却又简单的图片裁剪工具,它可以进行非常灵活的配置,支持手机端使用,支持包括 IE9 以上的现代浏览器。它可以用于满足诸如裁剪头像上传、商品图片编辑之类的需求。

Cropper.js 支持以下特性:

可交换图像文件格式(英语:Exchangeable image file format,官方简称 Exif),是专门为数码相机的照片设定的文件格式,可以记录数码照片的属性信息和拍摄数据。Exif 可以附加于 JPEG、TIFF、RIFF 等文件之中,为其增加有关数码相机拍摄信息的内容和索引图或图像处理软件的版本信息。

Exif 信息以 0xFFE1 作为开头标记,后两个字节表示 Exif 信息的长度。所以 Exif 信息最大为 64 kB,而内部采用 TIFF 格式。

「使用示例」

//import'cropperjs/dist/cropper.css'; importCropperfrom'cropperjs'; constimage=document.getElementById('image'); constcropper=newCropper(image,{ aspectRatio:16/9, crop(event){ console.log(event.detail.x); console.log(event.detail.y); console.log(event.detail.width); console.log(event.detail.height); console.log(event.detail.rotate); console.log(event.detail.scaleX); console.log(event.detail.scaleY); }, });

「在线示例」

https://fengyuanchen.github.io/cropperjs/

矢量图的用途,矢量图的特点及用途(7)

2.4 compressorjs

JavaScript image compressor.

https://github.com/fengyuanchen/compressorjs

compressorjs 是 JavaScript 图像压缩器。使用浏览器原生的 canvas.toBlob API 进行压缩工作,这意味着它是有损压缩。通常的使用场景是,在浏览器端图片上传之前对其进行预压缩。

在浏览器端要实现图片压缩,除了使用 canvas.toBlob API 之外,还可以使用 Canvas 提供的另一个 API,即 toDataURL API,它接收 type 和encoderOptions 两个可选参数。

其中 type 表示图片格式,默认为 image/png。而 encoderOptions用于表示图片的质量,在指定图片格式为 image/jpeg 或 image/webp的情况下,可以从 0 到 1 的区间内选择图片的质量。如果超出取值范围,将会使用默认值 0.92,其他参数会被忽略。

相比 canvas.toDataURL API 来说,canvas.toBlob API 是异步的,因此多了个 callback 参数,这个 callback 回调方法默认的第一个参数就是转换好的 blob 文件信息。canvas.toBlob 的签名如下:

canvas.toBlob(callback,mimeType,qualityArgument)

「使用示例」

importaxiosfrom'axios'; importCompressorfrom'compressorjs'; //<inputtype="file"id="file"accept="image/*"> document.getElementById('file').addEventListener('change',(e)=>{ constfile=e.target.files[0]; if(!file){ return; } newCompressor(file,{ quality:0.6, success(result){ constformData=newFormData(); //Thethirdparameterisrequiredforserver formData.append('file',result,result.name); //SendthecompressedimagefiletoserverwithXMLHttpRequest. axios.post('/path/to/upload',formData).then(()=>{ console.log('Uploadsuccess'); }); }, error(err){ console.log(err.message); }, }); });

「在线示例」

https://fengyuanchen.github.io/compressorjs/

矢量图的用途,矢量图的特点及用途(8)

上一页1234下一页

栏目热文

文档排行

本站推荐

Copyright © 2018 - 2021 www.yd166.com., All Rights Reserved.