Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@pixi/canvas-extract

Package Overview
Dependencies
Maintainers
1
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pixi/canvas-extract - npm Package Compare versions

Comparing version 5.2.4 to 5.3.0

277

dist/canvas-extract.js
/*!
* @pixi/canvas-extract - v5.2.4
* Compiled Sun, 03 May 2020 22:38:52 UTC
* @pixi/canvas-extract - v5.3.0
* Compiled Thu, 18 Jun 2020 23:27:40 UTC
*

@@ -9,7 +9,6 @@ * @pixi/canvas-extract is licensed under the MIT License.

this.PIXI = this.PIXI || {};
var _pixi_canvas_extract = (function (exports, core, utils, math) {
var _pixi_canvas_extract = (function (exports, core, utils, math, canvasRenderer) {
'use strict';
var TEMP_RECT = new math.Rectangle();
/**

@@ -23,157 +22,133 @@ * The extract manager provides functionality to export content from the renderers.

*/
var CanvasExtract = function CanvasExtract(renderer)
{
this.renderer = renderer;
var CanvasExtract = /** @class */ (function () {
/**
* Collection of methods for extracting data (image, pixels, etc.) from a display object or render texture
* @param {PIXI.CanvasRenderer} renderer - A reference to the current renderer
*/
function CanvasExtract(renderer) {
this.renderer = renderer;
}
/**
* Will return a HTML Image of the target
*
* @member {PIXI.CanvasExtract} extract
* @memberof PIXI.CanvasRenderer#
* @see PIXI.CanvasExtract
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @param {string} [format] - Image format, e.g. "image/jpeg" or "image/webp".
* @param {number} [quality] - JPEG or Webp compression from 0 to 1. Default is 0.92.
* @return {HTMLImageElement} HTML Image of the target
*/
renderer.extract = this;
};
/**
* Will return a HTML Image of the target
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @param {string} [format] - Image format, e.g. "image/jpeg" or "image/webp".
* @param {number} [quality] - JPEG or Webp compression from 0 to 1. Default is 0.92.
* @return {HTMLImageElement} HTML Image of the target
*/
CanvasExtract.prototype.image = function image (target, format, quality)
{
var image = new Image();
image.src = this.base64(target, format, quality);
return image;
};
/**
* Will return a a base64 encoded string of this target. It works by calling
* `CanvasExtract.getCanvas` and then running toDataURL on that.
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @param {string} [format] - Image format, e.g. "image/jpeg" or "image/webp".
* @param {number} [quality] - JPEG or Webp compression from 0 to 1. Default is 0.92.
* @return {string} A base64 encoded string of the texture.
*/
CanvasExtract.prototype.base64 = function base64 (target, format, quality)
{
return this.canvas(target).toDataURL(format, quality);
};
/**
* Creates a Canvas element, renders this target to it and then returns it.
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @return {HTMLCanvasElement} A Canvas element with the texture rendered on.
*/
CanvasExtract.prototype.canvas = function canvas (target)
{
var renderer = this.renderer;
var context;
var resolution;
var frame;
var renderTexture;
if (target)
{
if (target instanceof core.RenderTexture)
{
renderTexture = target;
CanvasExtract.prototype.image = function (target, format, quality) {
var image = new Image();
image.src = this.base64(target, format, quality);
return image;
};
/**
* Will return a a base64 encoded string of this target. It works by calling
* `CanvasExtract.getCanvas` and then running toDataURL on that.
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @param {string} [format] - Image format, e.g. "image/jpeg" or "image/webp".
* @param {number} [quality] - JPEG or Webp compression from 0 to 1. Default is 0.92.
* @return {string} A base64 encoded string of the texture.
*/
CanvasExtract.prototype.base64 = function (target, format, quality) {
return this.canvas(target).toDataURL(format, quality);
};
/**
* Creates a Canvas element, renders this target to it and then returns it.
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @return {HTMLCanvasElement} A Canvas element with the texture rendered on.
*/
CanvasExtract.prototype.canvas = function (target) {
var renderer = this.renderer;
var context;
var resolution;
var frame;
var renderTexture;
if (target) {
if (target instanceof core.RenderTexture) {
renderTexture = target;
}
else {
renderTexture = renderer.generateTexture(target);
}
}
else
{
renderTexture = renderer.generateTexture(target);
if (renderTexture) {
context = renderTexture.baseTexture._canvasRenderTarget.context;
resolution = renderTexture.baseTexture._canvasRenderTarget.resolution;
frame = renderTexture.frame;
}
}
if (renderTexture)
{
context = renderTexture.baseTexture._canvasRenderTarget.context;
resolution = renderTexture.baseTexture._canvasRenderTarget.resolution;
frame = renderTexture.frame;
}
else
{
context = renderer.rootContext;
resolution = renderer.resolution;
frame = TEMP_RECT;
frame.width = this.renderer.width;
frame.height = this.renderer.height;
}
var width = Math.floor((frame.width * resolution) + 1e-4);
var height = Math.floor((frame.height * resolution) + 1e-4);
var canvasBuffer = new utils.CanvasRenderTarget(width, height, 1);
var canvasData = context.getImageData(frame.x * resolution, frame.y * resolution, width, height);
canvasBuffer.context.putImageData(canvasData, 0, 0);
// send the canvas back..
return canvasBuffer.canvas;
};
/**
* Will return a one-dimensional array containing the pixel data of the entire texture in RGBA
* order, with integer values between 0 and 255 (included).
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @return {Uint8ClampedArray} One-dimensional array containing the pixel data of the entire texture
*/
CanvasExtract.prototype.pixels = function pixels (target)
{
var renderer = this.renderer;
var context;
var resolution;
var frame;
var renderTexture;
if (target)
{
if (target instanceof core.RenderTexture)
{
renderTexture = target;
else {
context = renderer.rootContext;
resolution = renderer.resolution;
frame = TEMP_RECT;
frame.width = this.renderer.width;
frame.height = this.renderer.height;
}
else
{
renderTexture = renderer.generateTexture(target);
var width = Math.floor((frame.width * resolution) + 1e-4);
var height = Math.floor((frame.height * resolution) + 1e-4);
var canvasBuffer = new utils.CanvasRenderTarget(width, height, 1);
var canvasData = context.getImageData(frame.x * resolution, frame.y * resolution, width, height);
canvasBuffer.context.putImageData(canvasData, 0, 0);
// send the canvas back..
return canvasBuffer.canvas;
};
/**
* Will return a one-dimensional array containing the pixel data of the entire texture in RGBA
* order, with integer values between 0 and 255 (included).
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @return {Uint8ClampedArray} One-dimensional array containing the pixel data of the entire texture
*/
CanvasExtract.prototype.pixels = function (target) {
var renderer = this.renderer;
var context;
var resolution;
var frame;
var renderTexture;
if (target) {
if (target instanceof core.RenderTexture) {
renderTexture = target;
}
else {
renderTexture = renderer.generateTexture(target);
}
}
}
if (renderTexture)
{
context = renderTexture.baseTexture._canvasRenderTarget.context;
resolution = renderTexture.baseTexture._canvasRenderTarget.resolution;
frame = renderTexture.frame;
}
else
{
context = renderer.rootContext;
frame = TEMP_RECT;
frame.width = renderer.width;
frame.height = renderer.height;
}
return context.getImageData(0, 0, frame.width * resolution, frame.height * resolution).data;
};
if (renderTexture) {
context = renderTexture.baseTexture._canvasRenderTarget.context;
resolution = renderTexture.baseTexture._canvasRenderTarget.resolution;
frame = renderTexture.frame;
}
else {
context = renderer.rootContext;
frame = TEMP_RECT;
frame.width = renderer.width;
frame.height = renderer.height;
}
return context.getImageData(0, 0, frame.width * resolution, frame.height * resolution).data;
};
/**
* Destroys the extract
*
*/
CanvasExtract.prototype.destroy = function () {
this.renderer = null;
};
return CanvasExtract;
}());
/**
* Destroys the extract
*
* @name PIXI.CanvasRenderer#extract
* @type {PIXI.CanvasExtract}
* @see PIXI.CanvasRenderer#plugins
* @deprecated since 5.3.0
*/
CanvasExtract.prototype.destroy = function destroy ()
{
this.renderer.extract = null;
this.renderer = null;
};
Object.defineProperty(canvasRenderer.CanvasRenderer.prototype, 'extract', {
get: function () {
utils.deprecation('v5.3.0', 'CanvasRenderer#extract is deprecated, use CanvasRenderer#plugins.extract');
return this.plugins.extract;
},
});

@@ -184,4 +159,4 @@ exports.CanvasExtract = CanvasExtract;

}({}, PIXI, PIXI.utils, PIXI));
}({}, PIXI, PIXI.utils, PIXI, PIXI));
Object.assign(this.PIXI, _pixi_canvas_extract);
//# sourceMappingURL=canvas-extract.js.map
/*!
* @pixi/canvas-extract - v5.2.4
* Compiled Sun, 03 May 2020 22:38:52 UTC
* @pixi/canvas-extract - v5.3.0
* Compiled Thu, 18 Jun 2020 23:27:40 UTC
*

@@ -8,3 +8,3 @@ * @pixi/canvas-extract is licensed under the MIT License.

*/
this.PIXI=this.PIXI||{};var _pixi_canvas_extract=function(e,t,r,a){"use strict";var n=new PIXI.Rectangle,i=function(e){this.renderer=e,e.extract=this};return i.prototype.image=function(e,t,r){var a=new Image;return a.src=this.base64(e,t,r),a},i.prototype.base64=function(e,t,r){return this.canvas(e).toDataURL(t,r)},i.prototype.canvas=function(e){var a,i,s,o,h=this.renderer;e&&(o=e instanceof t.RenderTexture?e:h.generateTexture(e)),o?(a=o.baseTexture._canvasRenderTarget.context,i=o.baseTexture._canvasRenderTarget.resolution,s=o.frame):(a=h.rootContext,i=h.resolution,(s=n).width=this.renderer.width,s.height=this.renderer.height);var c=Math.floor(s.width*i+1e-4),u=Math.floor(s.height*i+1e-4),d=new r.CanvasRenderTarget(c,u,1),g=a.getImageData(s.x*i,s.y*i,c,u);return d.context.putImageData(g,0,0),d.canvas},i.prototype.pixels=function(e){var r,a,i,s,o=this.renderer;return e&&(s=e instanceof t.RenderTexture?e:o.generateTexture(e)),s?(r=s.baseTexture._canvasRenderTarget.context,a=s.baseTexture._canvasRenderTarget.resolution,i=s.frame):(r=o.rootContext,(i=n).width=o.width,i.height=o.height),r.getImageData(0,0,i.width*a,i.height*a).data},i.prototype.destroy=function(){this.renderer.extract=null,this.renderer=null},e.CanvasExtract=i,e}({},PIXI,PIXI.utils);Object.assign(this.PIXI,_pixi_canvas_extract);
this.PIXI=this.PIXI||{};var _pixi_canvas_extract=function(e,t,r,a,n){"use strict";var i=new a.Rectangle,s=function(){function e(e){this.renderer=e}return e.prototype.image=function(e,t,r){var a=new Image;return a.src=this.base64(e,t,r),a},e.prototype.base64=function(e,t,r){return this.canvas(e).toDataURL(t,r)},e.prototype.canvas=function(e){var a,n,s,o,c=this.renderer;e&&(o=e instanceof t.RenderTexture?e:c.generateTexture(e)),o?(a=o.baseTexture._canvasRenderTarget.context,n=o.baseTexture._canvasRenderTarget.resolution,s=o.frame):(a=c.rootContext,n=c.resolution,(s=i).width=this.renderer.width,s.height=this.renderer.height);var u=Math.floor(s.width*n+1e-4),h=Math.floor(s.height*n+1e-4),d=new r.CanvasRenderTarget(u,h,1),g=a.getImageData(s.x*n,s.y*n,u,h);return d.context.putImageData(g,0,0),d.canvas},e.prototype.pixels=function(e){var r,a,n,s,o=this.renderer;return e&&(s=e instanceof t.RenderTexture?e:o.generateTexture(e)),s?(r=s.baseTexture._canvasRenderTarget.context,a=s.baseTexture._canvasRenderTarget.resolution,n=s.frame):(r=o.rootContext,(n=i).width=o.width,n.height=o.height),r.getImageData(0,0,n.width*a,n.height*a).data},e.prototype.destroy=function(){this.renderer=null},e}();return Object.defineProperty(n.CanvasRenderer.prototype,"extract",{get:function(){return r.deprecation("v5.3.0","CanvasRenderer#extract is deprecated, use CanvasRenderer#plugins.extract"),this.plugins.extract}}),e.CanvasExtract=s,e}({},PIXI,PIXI.utils,PIXI,PIXI);Object.assign(this.PIXI,_pixi_canvas_extract);
//# sourceMappingURL=canvas-extract.min.js.map
/*!
* @pixi/canvas-extract - v5.2.4
* Compiled Sun, 03 May 2020 22:38:52 UTC
* @pixi/canvas-extract - v5.3.0
* Compiled Thu, 18 Jun 2020 23:27:40 UTC
*

@@ -9,7 +9,7 @@ * @pixi/canvas-extract is licensed under the MIT License.

import { RenderTexture } from '@pixi/core';
import { CanvasRenderTarget } from '@pixi/utils';
import { CanvasRenderTarget, deprecation } from '@pixi/utils';
import { Rectangle } from '@pixi/math';
import { CanvasRenderer } from '@pixi/canvas-renderer';
var TEMP_RECT = new Rectangle();
/**

@@ -23,159 +23,135 @@ * The extract manager provides functionality to export content from the renderers.

*/
var CanvasExtract = function CanvasExtract(renderer)
{
this.renderer = renderer;
var CanvasExtract = /** @class */ (function () {
/**
* Collection of methods for extracting data (image, pixels, etc.) from a display object or render texture
* @param {PIXI.CanvasRenderer} renderer - A reference to the current renderer
*/
function CanvasExtract(renderer) {
this.renderer = renderer;
}
/**
* Will return a HTML Image of the target
*
* @member {PIXI.CanvasExtract} extract
* @memberof PIXI.CanvasRenderer#
* @see PIXI.CanvasExtract
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @param {string} [format] - Image format, e.g. "image/jpeg" or "image/webp".
* @param {number} [quality] - JPEG or Webp compression from 0 to 1. Default is 0.92.
* @return {HTMLImageElement} HTML Image of the target
*/
renderer.extract = this;
};
/**
* Will return a HTML Image of the target
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @param {string} [format] - Image format, e.g. "image/jpeg" or "image/webp".
* @param {number} [quality] - JPEG or Webp compression from 0 to 1. Default is 0.92.
* @return {HTMLImageElement} HTML Image of the target
*/
CanvasExtract.prototype.image = function image (target, format, quality)
{
var image = new Image();
image.src = this.base64(target, format, quality);
return image;
};
/**
* Will return a a base64 encoded string of this target. It works by calling
* `CanvasExtract.getCanvas` and then running toDataURL on that.
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @param {string} [format] - Image format, e.g. "image/jpeg" or "image/webp".
* @param {number} [quality] - JPEG or Webp compression from 0 to 1. Default is 0.92.
* @return {string} A base64 encoded string of the texture.
*/
CanvasExtract.prototype.base64 = function base64 (target, format, quality)
{
return this.canvas(target).toDataURL(format, quality);
};
/**
* Creates a Canvas element, renders this target to it and then returns it.
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @return {HTMLCanvasElement} A Canvas element with the texture rendered on.
*/
CanvasExtract.prototype.canvas = function canvas (target)
{
var renderer = this.renderer;
var context;
var resolution;
var frame;
var renderTexture;
if (target)
{
if (target instanceof RenderTexture)
{
renderTexture = target;
CanvasExtract.prototype.image = function (target, format, quality) {
var image = new Image();
image.src = this.base64(target, format, quality);
return image;
};
/**
* Will return a a base64 encoded string of this target. It works by calling
* `CanvasExtract.getCanvas` and then running toDataURL on that.
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @param {string} [format] - Image format, e.g. "image/jpeg" or "image/webp".
* @param {number} [quality] - JPEG or Webp compression from 0 to 1. Default is 0.92.
* @return {string} A base64 encoded string of the texture.
*/
CanvasExtract.prototype.base64 = function (target, format, quality) {
return this.canvas(target).toDataURL(format, quality);
};
/**
* Creates a Canvas element, renders this target to it and then returns it.
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @return {HTMLCanvasElement} A Canvas element with the texture rendered on.
*/
CanvasExtract.prototype.canvas = function (target) {
var renderer = this.renderer;
var context;
var resolution;
var frame;
var renderTexture;
if (target) {
if (target instanceof RenderTexture) {
renderTexture = target;
}
else {
renderTexture = renderer.generateTexture(target);
}
}
else
{
renderTexture = renderer.generateTexture(target);
if (renderTexture) {
context = renderTexture.baseTexture._canvasRenderTarget.context;
resolution = renderTexture.baseTexture._canvasRenderTarget.resolution;
frame = renderTexture.frame;
}
}
if (renderTexture)
{
context = renderTexture.baseTexture._canvasRenderTarget.context;
resolution = renderTexture.baseTexture._canvasRenderTarget.resolution;
frame = renderTexture.frame;
}
else
{
context = renderer.rootContext;
resolution = renderer.resolution;
frame = TEMP_RECT;
frame.width = this.renderer.width;
frame.height = this.renderer.height;
}
var width = Math.floor((frame.width * resolution) + 1e-4);
var height = Math.floor((frame.height * resolution) + 1e-4);
var canvasBuffer = new CanvasRenderTarget(width, height, 1);
var canvasData = context.getImageData(frame.x * resolution, frame.y * resolution, width, height);
canvasBuffer.context.putImageData(canvasData, 0, 0);
// send the canvas back..
return canvasBuffer.canvas;
};
/**
* Will return a one-dimensional array containing the pixel data of the entire texture in RGBA
* order, with integer values between 0 and 255 (included).
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @return {Uint8ClampedArray} One-dimensional array containing the pixel data of the entire texture
*/
CanvasExtract.prototype.pixels = function pixels (target)
{
var renderer = this.renderer;
var context;
var resolution;
var frame;
var renderTexture;
if (target)
{
if (target instanceof RenderTexture)
{
renderTexture = target;
else {
context = renderer.rootContext;
resolution = renderer.resolution;
frame = TEMP_RECT;
frame.width = this.renderer.width;
frame.height = this.renderer.height;
}
else
{
renderTexture = renderer.generateTexture(target);
var width = Math.floor((frame.width * resolution) + 1e-4);
var height = Math.floor((frame.height * resolution) + 1e-4);
var canvasBuffer = new CanvasRenderTarget(width, height, 1);
var canvasData = context.getImageData(frame.x * resolution, frame.y * resolution, width, height);
canvasBuffer.context.putImageData(canvasData, 0, 0);
// send the canvas back..
return canvasBuffer.canvas;
};
/**
* Will return a one-dimensional array containing the pixel data of the entire texture in RGBA
* order, with integer values between 0 and 255 (included).
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @return {Uint8ClampedArray} One-dimensional array containing the pixel data of the entire texture
*/
CanvasExtract.prototype.pixels = function (target) {
var renderer = this.renderer;
var context;
var resolution;
var frame;
var renderTexture;
if (target) {
if (target instanceof RenderTexture) {
renderTexture = target;
}
else {
renderTexture = renderer.generateTexture(target);
}
}
}
if (renderTexture)
{
context = renderTexture.baseTexture._canvasRenderTarget.context;
resolution = renderTexture.baseTexture._canvasRenderTarget.resolution;
frame = renderTexture.frame;
}
else
{
context = renderer.rootContext;
frame = TEMP_RECT;
frame.width = renderer.width;
frame.height = renderer.height;
}
return context.getImageData(0, 0, frame.width * resolution, frame.height * resolution).data;
};
if (renderTexture) {
context = renderTexture.baseTexture._canvasRenderTarget.context;
resolution = renderTexture.baseTexture._canvasRenderTarget.resolution;
frame = renderTexture.frame;
}
else {
context = renderer.rootContext;
frame = TEMP_RECT;
frame.width = renderer.width;
frame.height = renderer.height;
}
return context.getImageData(0, 0, frame.width * resolution, frame.height * resolution).data;
};
/**
* Destroys the extract
*
*/
CanvasExtract.prototype.destroy = function () {
this.renderer = null;
};
return CanvasExtract;
}());
/**
* Destroys the extract
*
* @name PIXI.CanvasRenderer#extract
* @type {PIXI.CanvasExtract}
* @see PIXI.CanvasRenderer#plugins
* @deprecated since 5.3.0
*/
CanvasExtract.prototype.destroy = function destroy ()
{
this.renderer.extract = null;
this.renderer = null;
};
Object.defineProperty(CanvasRenderer.prototype, 'extract', {
get: function () {
deprecation('v5.3.0', 'CanvasRenderer#extract is deprecated, use CanvasRenderer#plugins.extract');
return this.plugins.extract;
},
});
export { CanvasExtract };
//# sourceMappingURL=canvas-extract.es.js.map
/*!
* @pixi/canvas-extract - v5.2.4
* Compiled Sun, 03 May 2020 22:38:52 UTC
* @pixi/canvas-extract - v5.3.0
* Compiled Thu, 18 Jun 2020 23:27:40 UTC
*

@@ -15,5 +15,5 @@ * @pixi/canvas-extract is licensed under the MIT License.

var math = require('@pixi/math');
var canvasRenderer = require('@pixi/canvas-renderer');
var TEMP_RECT = new math.Rectangle();
/**

@@ -27,159 +27,135 @@ * The extract manager provides functionality to export content from the renderers.

*/
var CanvasExtract = function CanvasExtract(renderer)
{
this.renderer = renderer;
var CanvasExtract = /** @class */ (function () {
/**
* Collection of methods for extracting data (image, pixels, etc.) from a display object or render texture
* @param {PIXI.CanvasRenderer} renderer - A reference to the current renderer
*/
function CanvasExtract(renderer) {
this.renderer = renderer;
}
/**
* Will return a HTML Image of the target
*
* @member {PIXI.CanvasExtract} extract
* @memberof PIXI.CanvasRenderer#
* @see PIXI.CanvasExtract
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @param {string} [format] - Image format, e.g. "image/jpeg" or "image/webp".
* @param {number} [quality] - JPEG or Webp compression from 0 to 1. Default is 0.92.
* @return {HTMLImageElement} HTML Image of the target
*/
renderer.extract = this;
};
/**
* Will return a HTML Image of the target
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @param {string} [format] - Image format, e.g. "image/jpeg" or "image/webp".
* @param {number} [quality] - JPEG or Webp compression from 0 to 1. Default is 0.92.
* @return {HTMLImageElement} HTML Image of the target
*/
CanvasExtract.prototype.image = function image (target, format, quality)
{
var image = new Image();
image.src = this.base64(target, format, quality);
return image;
};
/**
* Will return a a base64 encoded string of this target. It works by calling
* `CanvasExtract.getCanvas` and then running toDataURL on that.
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @param {string} [format] - Image format, e.g. "image/jpeg" or "image/webp".
* @param {number} [quality] - JPEG or Webp compression from 0 to 1. Default is 0.92.
* @return {string} A base64 encoded string of the texture.
*/
CanvasExtract.prototype.base64 = function base64 (target, format, quality)
{
return this.canvas(target).toDataURL(format, quality);
};
/**
* Creates a Canvas element, renders this target to it and then returns it.
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @return {HTMLCanvasElement} A Canvas element with the texture rendered on.
*/
CanvasExtract.prototype.canvas = function canvas (target)
{
var renderer = this.renderer;
var context;
var resolution;
var frame;
var renderTexture;
if (target)
{
if (target instanceof core.RenderTexture)
{
renderTexture = target;
CanvasExtract.prototype.image = function (target, format, quality) {
var image = new Image();
image.src = this.base64(target, format, quality);
return image;
};
/**
* Will return a a base64 encoded string of this target. It works by calling
* `CanvasExtract.getCanvas` and then running toDataURL on that.
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @param {string} [format] - Image format, e.g. "image/jpeg" or "image/webp".
* @param {number} [quality] - JPEG or Webp compression from 0 to 1. Default is 0.92.
* @return {string} A base64 encoded string of the texture.
*/
CanvasExtract.prototype.base64 = function (target, format, quality) {
return this.canvas(target).toDataURL(format, quality);
};
/**
* Creates a Canvas element, renders this target to it and then returns it.
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @return {HTMLCanvasElement} A Canvas element with the texture rendered on.
*/
CanvasExtract.prototype.canvas = function (target) {
var renderer = this.renderer;
var context;
var resolution;
var frame;
var renderTexture;
if (target) {
if (target instanceof core.RenderTexture) {
renderTexture = target;
}
else {
renderTexture = renderer.generateTexture(target);
}
}
else
{
renderTexture = renderer.generateTexture(target);
if (renderTexture) {
context = renderTexture.baseTexture._canvasRenderTarget.context;
resolution = renderTexture.baseTexture._canvasRenderTarget.resolution;
frame = renderTexture.frame;
}
}
if (renderTexture)
{
context = renderTexture.baseTexture._canvasRenderTarget.context;
resolution = renderTexture.baseTexture._canvasRenderTarget.resolution;
frame = renderTexture.frame;
}
else
{
context = renderer.rootContext;
resolution = renderer.resolution;
frame = TEMP_RECT;
frame.width = this.renderer.width;
frame.height = this.renderer.height;
}
var width = Math.floor((frame.width * resolution) + 1e-4);
var height = Math.floor((frame.height * resolution) + 1e-4);
var canvasBuffer = new utils.CanvasRenderTarget(width, height, 1);
var canvasData = context.getImageData(frame.x * resolution, frame.y * resolution, width, height);
canvasBuffer.context.putImageData(canvasData, 0, 0);
// send the canvas back..
return canvasBuffer.canvas;
};
/**
* Will return a one-dimensional array containing the pixel data of the entire texture in RGBA
* order, with integer values between 0 and 255 (included).
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @return {Uint8ClampedArray} One-dimensional array containing the pixel data of the entire texture
*/
CanvasExtract.prototype.pixels = function pixels (target)
{
var renderer = this.renderer;
var context;
var resolution;
var frame;
var renderTexture;
if (target)
{
if (target instanceof core.RenderTexture)
{
renderTexture = target;
else {
context = renderer.rootContext;
resolution = renderer.resolution;
frame = TEMP_RECT;
frame.width = this.renderer.width;
frame.height = this.renderer.height;
}
else
{
renderTexture = renderer.generateTexture(target);
var width = Math.floor((frame.width * resolution) + 1e-4);
var height = Math.floor((frame.height * resolution) + 1e-4);
var canvasBuffer = new utils.CanvasRenderTarget(width, height, 1);
var canvasData = context.getImageData(frame.x * resolution, frame.y * resolution, width, height);
canvasBuffer.context.putImageData(canvasData, 0, 0);
// send the canvas back..
return canvasBuffer.canvas;
};
/**
* Will return a one-dimensional array containing the pixel data of the entire texture in RGBA
* order, with integer values between 0 and 255 (included).
*
* @param {PIXI.DisplayObject|PIXI.RenderTexture} target - A displayObject or renderTexture
* to convert. If left empty will use the main renderer
* @return {Uint8ClampedArray} One-dimensional array containing the pixel data of the entire texture
*/
CanvasExtract.prototype.pixels = function (target) {
var renderer = this.renderer;
var context;
var resolution;
var frame;
var renderTexture;
if (target) {
if (target instanceof core.RenderTexture) {
renderTexture = target;
}
else {
renderTexture = renderer.generateTexture(target);
}
}
}
if (renderTexture)
{
context = renderTexture.baseTexture._canvasRenderTarget.context;
resolution = renderTexture.baseTexture._canvasRenderTarget.resolution;
frame = renderTexture.frame;
}
else
{
context = renderer.rootContext;
frame = TEMP_RECT;
frame.width = renderer.width;
frame.height = renderer.height;
}
return context.getImageData(0, 0, frame.width * resolution, frame.height * resolution).data;
};
if (renderTexture) {
context = renderTexture.baseTexture._canvasRenderTarget.context;
resolution = renderTexture.baseTexture._canvasRenderTarget.resolution;
frame = renderTexture.frame;
}
else {
context = renderer.rootContext;
frame = TEMP_RECT;
frame.width = renderer.width;
frame.height = renderer.height;
}
return context.getImageData(0, 0, frame.width * resolution, frame.height * resolution).data;
};
/**
* Destroys the extract
*
*/
CanvasExtract.prototype.destroy = function () {
this.renderer = null;
};
return CanvasExtract;
}());
/**
* Destroys the extract
*
* @name PIXI.CanvasRenderer#extract
* @type {PIXI.CanvasExtract}
* @see PIXI.CanvasRenderer#plugins
* @deprecated since 5.3.0
*/
CanvasExtract.prototype.destroy = function destroy ()
{
this.renderer.extract = null;
this.renderer = null;
};
Object.defineProperty(canvasRenderer.CanvasRenderer.prototype, 'extract', {
get: function () {
utils.deprecation('v5.3.0', 'CanvasRenderer#extract is deprecated, use CanvasRenderer#plugins.extract');
return this.plugins.extract;
},
});
exports.CanvasExtract = CanvasExtract;
//# sourceMappingURL=canvas-extract.js.map
{
"name": "@pixi/canvas-extract",
"version": "5.2.4",
"version": "5.3.0",
"main": "lib/canvas-extract.js",

@@ -27,7 +27,9 @@ "module": "lib/canvas-extract.es.js",

"dependencies": {
"@pixi/core": "5.2.4",
"@pixi/math": "5.2.4",
"@pixi/utils": "5.2.4"
"@pixi/canvas-renderer": "5.3.0",
"@pixi/core": "5.3.0",
"@pixi/display": "5.3.0",
"@pixi/math": "5.3.0",
"@pixi/utils": "5.3.0"
},
"gitHead": "71c6b3b2061af4a4f3a95a265d46e933b8befc2c"
"gitHead": "a9b7b32a9c0aeb3d9c42ef04b2c2a39be1cd0880"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc