2

Comprehensive Image Processing on Browsers

 3 years ago
source link: https://vivaxyblog.github.io/2019/11/06/comprehensive-image-processing-on-browsers.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Comprehensive Image Processing on Browsers

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

Image Data Types

<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.

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.

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

© Copyright 2011 ~ 2021 by vivaxy

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK