Browse Source

Support CORS-enabled images with crossOrigin option (#82)

pull/64/merge
Trevor Blades 5 years ago
committed by GitHub
parent
commit
154472e17e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      README.md
  2. 4
      src/index.js

7
README.md

@ -166,6 +166,13 @@ Default: `undefined`
Canvas implementation to be used to allow usage outside of the browser. e.g Node.js with node-canvas.
##### options.crossOrigin
Type: `string`<br>
Default: `undefined`
The `crossOrigin` attribute that `Image` instances should use. e.g `Anonymous` to [support CORS-enabled images](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image).
## License
MIT © Luke Childs

4
src/index.js

@ -4,7 +4,8 @@ const defaultOptions = {
quality: 0.92,
width: undefined,
height: undefined,
Canvas: undefined
Canvas: undefined,
crossOrigin: undefined
};
// Return Promise
@ -27,6 +28,7 @@ const mergeImages = (sources = [], options = {}) => new Promise(resolve => {
// Resolve source and img when loaded
const img = new Image();
img.crossOrigin = options.crossOrigin;
img.onerror = () => reject(new Error('Couldn\'t load image'));
img.onload = () => resolve(Object.assign({}, source, { img }));
img.src = source.src;

Loading…
Cancel
Save