-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All the encoders that Chrome/Safari/Firefox support out of the box. (#74
- Loading branch information
1 parent
807a76d
commit 3867448
Showing
10 changed files
with
134 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { canvasEncode } from '../../lib/util'; | ||
import { canvasEncodeTest } from '../generic/util'; | ||
|
||
export interface EncodeOptions { } | ||
export interface EncoderState { type: typeof type; options: EncodeOptions; } | ||
|
||
export const type = 'browser-bmp'; | ||
export const label = 'Browser BMP'; | ||
export const mimeType = 'image/bmp'; | ||
export const extension = 'bmp'; | ||
export const defaultOptions: EncodeOptions = {}; | ||
export const featureTest = () => canvasEncodeTest(mimeType); | ||
|
||
export function encode(data: ImageData, options: EncodeOptions) { | ||
return canvasEncode(data, mimeType); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { canvasEncode } from '../../lib/util'; | ||
import { canvasEncodeTest } from '../generic/util'; | ||
|
||
export interface EncodeOptions {} | ||
export interface EncoderState { type: typeof type; options: EncodeOptions; } | ||
|
||
export const type = 'browser-gif'; | ||
export const label = 'Browser GIF'; | ||
export const mimeType = 'image/gif'; | ||
export const extension = 'gif'; | ||
export const defaultOptions: EncodeOptions = {}; | ||
export const featureTest = () => canvasEncodeTest(mimeType); | ||
|
||
export function encode(data: ImageData, options: EncodeOptions) { | ||
return canvasEncode(data, mimeType); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { canvasEncode } from '../../lib/util'; | ||
import { canvasEncodeTest } from '../generic/util'; | ||
|
||
export interface EncodeOptions { } | ||
export interface EncoderState { type: typeof type; options: EncodeOptions; } | ||
|
||
export const type = 'browser-jp2'; | ||
export const label = 'Browser JPEG 2000'; | ||
export const mimeType = 'image/jp2'; | ||
export const extension = 'jp2'; | ||
export const defaultOptions: EncodeOptions = {}; | ||
export const featureTest = () => canvasEncodeTest(mimeType); | ||
|
||
export function encode(data: ImageData, options: EncodeOptions) { | ||
return canvasEncode(data, mimeType); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { canvasEncode } from '../../lib/util'; | ||
import { canvasEncodeTest } from '../generic/util'; | ||
|
||
export interface EncodeOptions { } | ||
export interface EncoderState { type: typeof type; options: EncodeOptions; } | ||
|
||
export const type = 'browser-pdf'; | ||
export const label = 'Browser PDF'; | ||
export const mimeType = 'application/pdf'; | ||
export const extension = 'pdf'; | ||
export const defaultOptions: EncodeOptions = {}; | ||
export const featureTest = () => canvasEncodeTest(mimeType); | ||
|
||
export function encode(data: ImageData, options: EncodeOptions) { | ||
return canvasEncode(data, mimeType); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { canvasEncode } from '../../lib/util'; | ||
import { canvasEncodeTest } from '../generic/util'; | ||
|
||
export interface EncodeOptions { } | ||
export interface EncoderState { type: typeof type; options: EncodeOptions; } | ||
|
||
export const type = 'browser-tiff'; | ||
export const label = 'Browser TIFF'; | ||
export const mimeType = 'image/tiff'; | ||
export const extension = 'tiff'; | ||
export const defaultOptions: EncodeOptions = {}; | ||
export const featureTest = () => canvasEncodeTest(mimeType); | ||
|
||
export function encode(data: ImageData, options: EncodeOptions) { | ||
return canvasEncode(data, mimeType); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { canvasEncode } from '../../lib/util'; | ||
|
||
export async function canvasEncodeTest(mimeType: string) { | ||
try { | ||
const blob = await canvasEncode(new ImageData(1, 1), mimeType); | ||
// According to the spec, the blob should be null if the format isn't supported… | ||
if (!blob) return false; | ||
// …but Safari & Firefox fall back to PNG, so we need to check the mime type. | ||
return blob.type === mimeType; | ||
} catch (err) { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters