惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
I
InfoQ
B
Blog RSS Feed
D
Docker
GbyAI
GbyAI
N
Netflix TechBlog - Medium
Y
Y Combinator Blog
F
Fortinet All Blogs
P
Proofpoint News Feed
Microsoft Azure Blog
Microsoft Azure Blog
人人都是产品经理
人人都是产品经理
Martin Fowler
Martin Fowler
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
M
MIT News - Artificial intelligence
C
Check Point Blog
Vercel News
Vercel News
云风的 BLOG
云风的 BLOG
博客园 - Franky
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
V2EX
Last Week in AI
Last Week in AI
L
LangChain Blog

vivaxy's Blog

SameSite Cookies 解读 - vivaxy's Blog VSCode Conventional Commits 插件 - vivaxy's Blog VSCode Conventional Commits Extension - vivaxy's Blog How Babel Is Built - vivaxy's Blog 一步一步解码 PNG 图片 - vivaxy's Blog Babel 的工程化实现 - vivaxy's Blog 浏览器图像转换手册 - vivaxy's Blog Decoding A PNG Image with JavaScript Step by Step Use npm Registry to Restric Installing Client Alfred 4 Workflow Open in VSCode Git Tag And Push Git Tag 基于 Custom Elements 的组件化开发 - vivaxy's Blog JavaScript PNG 图片编码和解码 - vivaxy's Blog 如何在多个模块中共享异步数据 - vivaxy's Blog JavaScript 函数式编程初窥 - vivaxy's Blog 用纯 CSS 实现弹窗 - vivaxy's Blog 在浏览器中使用 JavaScript 模块 - vivaxy's Blog Karabiner Elements Hyper 改键设置 - vivaxy's Blog Levenshtein 距离 - vivaxy's Blog Levenshtein 距离 - vivaxy's Blog
Comprehensive Image Processing on Browsers
vivaxy · 2019-11-06 · via vivaxy's Blog

Images can be represented in different types. They can be summarized as 5 types: DOM, URL, File, ImageData and Buffer.

Image Data Types

DOM

<img>

<img> elements load images from URL(e.g. Data URLs, HTTP URLs or Object URLs).

<canvas>

<canvas> elements draw images by canvas API drawImage from <img> elements.

URL

Data URLs

Data URLs carries base64 encoded image data. Image binary can be decoded from Data URLs. Data URL image file size is a little larger than the original binary data.

HTTP URLs

HTTP URLs represent images stored on servers. HTTP URLs are used to fetch image data from servers.

Object URLs

Object URLs represent the File or Blob object. Object URLs can be created by createObjectURL API, and released by revokeObjectURL API. The object is stored in browser memory and can be accessed by a short Object URL.

File

Blob

A Blob object represents a file-like object of binary data. It contains a readyonly size property and a readyonly type property. You can retrieve the binary data by slice, stream, text and arrayBuffer methods.

File

A File object is a special Blob object. In addtion to the Blob properties and methods, the File object contains lastModified, name properties.

ImageData

A ImageData object is a JavaScript object containing width, height and data properties, represents the image width, height and pixel data. data property is an one-dimensional array, containing data like [R, G, B, A, R, G, B, A]. Each [R, G, B, A] represents a pixel. You can create a ImageData by <canvas> API createImageData or the ImageData constructor.

Buffer

ArrayBuffer

There is only one way of accessing the binary data on browsers ArrayBuffer. An ArrayBuffer represents a raw binary data buffer of the image. ArrayBuffer cannot be read and written. You can only convert an ArrayBuffer to DataView or TypedArray to read and write binary data.

Buffer

In Node.js, Buffer is a special Uint8Array with some optimizations.

Convert within ArrayBuffer, DataView, TypedArray and Buffer

How to convert within `ArrayBuffer`, `DataView`, TypedArray and `Buffer`

Conver within DOM, URL, File, ImageData and Buffer

How to conver within DOM, URL, File, `ImageData` and Buffer

Reference