How to use _onMakeImage method in wpt

Best JavaScript code snippet using wpt

Drawing.cls.js

Source:Drawing.cls.js Github

copy

Full Screen

1/*!2 * tangram.js framework source code3 *4 * extend_static_methods graphic/canvas5 *6 * Date: 2017-04-067 */8tangram.block([9 '$_/util/bool.xtd',10 '$_/painter/QRCode/SVGDrawing.cls'11], function(pandora, global, undefined) {12 var _ = pandora,13 declare = pandora.declareClass,14 document = global.document;15 var useSVG = document.documentElement.tagName.toLowerCase() === "svg";16 if (useSVG) {17 _.painter.QRCode.Drawing = _.painter.QRCode.SVGDrawing;18 } else {19 if (_.util.bool.isSupportCanvas()) {20 var _onMakeImage = function() {21 this.ElementImage.src = this.ElementCanvas.toDataURL("image/png");22 this.ElementImage.style.display = "block";23 this.ElementCanvas.style.display = "none";24 }25 // Android 2.1 bug workaround26 // http://code.google.com/p/android/issues/detail?id=514127 if (this.isAndroid && this.isAndroid <= 2.1) {28 var factor = 1 / window.devicePixelRatio;29 var drawImage = CanvasRenderingContext2D.prototype.drawImage;30 CanvasRenderingContext2D.prototype.drawImage = function(image, sx, sy, sw, sh, dx, dy, dw, dh) {31 if (("nodeName" in image) && /img/i.test(image.nodeName)) {32 for (var i = arguments.length - 1; i >= 1; i--) {33 arguments[i] = arguments[i] * factor;34 }35 } else if (typeof dw == "undefined") {36 arguments[1] *= factor;37 arguments[2] *= factor;38 arguments[3] *= factor;39 arguments[4] *= factor;40 }41 drawImage.apply(this, arguments);42 };43 }44 /**45 * Check whether the user's browser supports Data URI or not46 * 47 * @private48 * @param {Function} success Occurs if it supports Data URI49 * @param {Function} fail Occurs if it doesn't support Data URI50 */51 var setSafeDataURI = function(successCallback, failCallback) {52 var that = this;53 that.fail = failCallback;54 that.success = successCallback;55 // Check it just once56 if (that.isSupportDataURI === null) {57 var el = document.createElement("img");58 var error = function() {59 that.isSupportDataURI = false;60 if (that.fail) {61 that.fail.call(that);62 }63 };64 var success = function() {65 that.isSupportDataURI = true;66 if (that.success) {67 that.success.call(that);68 }69 };70 el.onabort = error;71 el.onerror = error;72 el.onload = success;73 el.src = "data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDtangram.jsE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="; // the Image contains 1px data.74 return;75 } else if (that.isSupportDataURI === true && that.success) {76 that.success.call(that);77 } else if (that.isSupportDataURI === false && that.fail) {78 that.fail.call(that);79 }80 };81 declare('painter.QRCode.Drawing', {82 _init: function(elem, options) {83 this.isPainted = false;84 this.isAndroid = _.util.bool.isAndroid();85 this.options = options;86 this.ElementCanvas = document.createElement("canvas");87 this.ElementCanvas.width = options.width;88 this.ElementCanvas.height = options.height;89 elem.appendChild(this.ElementCanvas);90 this.Element = elem;91 this.context = this.ElementCanvas.getContext("2d");92 this.isPainted = false;93 this.ElementImage = document.createElement("img");94 this.ElementImage.alt = "Scan me!";95 this.ElementImage.style.display = "none";96 this.Element.appendChild(this.ElementImage);97 this.isSupportDataURI = null;98 },99 draw: function(QRCode) {100 var elemImage = this.ElementImage;101 var context = this.context;102 var options = this.options;103 var nCount = QRCode.getModuleCount();104 var nWidth = options.width / nCount;105 var nHeight = options.height / nCount;106 var nRoundedWidth = Math.round(nWidth);107 var nRoundedHeight = Math.round(nHeight);108 elemImage.style.display = "none";109 this.clear();110 for (var row = 0; row < nCount; row++) {111 for (var col = 0; col < nCount; col++) {112 var bIsDark = QRCode.isDark(row, col);113 var nLeft = col * nWidth;114 var nTop = row * nHeight;115 context.strokeStyle = bIsDark ? options.colorDark : options.colorLight;116 context.lineWidth = 1;117 context.fillStyle = bIsDark ? options.colorDark : options.colorLight;118 context.fillRect(nLeft, nTop, nWidth, nHeight);119 context.strokeRect(120 Math.floor(nLeft) + 0.5,121 Math.floor(nTop) + 0.5,122 nRoundedWidth,123 nRoundedHeight124 );125 context.strokeRect(126 Math.ceil(nLeft) - 0.5,127 Math.ceil(nTop) - 0.5,128 nRoundedWidth,129 nRoundedHeight130 );131 }132 }133 this.isPainted = true;134 },135 /**136 * Make the image from Canvas if the browser supports Data URI.137 */138 makeImage: function() {139 if (this.isPainted) {140 setSafeDataURI.call(this, _onMakeImage);141 }142 },143 /**144 * Return whether the QRCode is painted or not145 * 146 * @return {Boolean}147 */148 isPainted: function() {149 return this.isPainted;150 },151 /**152 * Clear the QRCode153 */154 clear: function() {155 this.context.clearRect(0, 0, this.ElementCanvas.width, this.ElementCanvas.height);156 this.isPainted = false;157 },158 /**159 * @private160 * @param {Number} nNumber161 */162 round: function(nNumber) {163 if (!nNumber) {164 return nNumber;165 }166 return Math.floor(nNumber * 1000) / 1000;167 }168 });169 } else {170 declare('painter.QRCode.Drawing', {171 _init: function(el, options) {172 this.Element = el;173 this.options = options;174 },175 /**176 * Draw the QRCode177 * 178 * @param {QRCode} QRCode179 */180 draw: function(QRCode) {181 var options = this.options;182 var elem = this.Element;183 var nCount = QRCode.getModuleCount();184 var nWidth = Math.floor(options.width / nCount);185 var nHeight = Math.floor(options.height / nCount);186 var aHTML = ['<table style="border:0;border-collapse:collapse;">'];187 for (var row = 0; row < nCount; row++) {188 aHTML.push('<tr>');189 for (var col = 0; col < nCount; col++) {190 aHTML.push('<td style="border:0;border-collapse:collapse;padding:0;margin:0;width:' + nWidth + 'px;height:' + nHeight + 'px;background-color:' + (QRCode.isDark(row, col) ? options.colorDark : options.colorLight) + ';"></td>');191 }192 aHTML.push('</tr>');193 }194 aHTML.push('</table>');195 elem.innerHTML = aHTML.join('');196 // Fix the margin values as real size.197 var elTable = elem.childNodes[0];198 var nLeftMarginTable = (options.width - elTable.offsetWidth) / 2;199 var nTopMarginTable = (options.height - elTable.offsetHeight) / 2;200 if (nLeftMarginTable > 0 && nTopMarginTable > 0) {201 elTable.style.margin = nTopMarginTable + "px " + nLeftMarginTable + "px";202 }203 },204 /**205 * Clear the QRCode206 */207 clear: function() {208 this.Element.innerHTML = '';209 }210 });211 }212 }...

Full Screen

Full Screen

Drawing.ts

Source:Drawing.ts Github

copy

Full Screen

...48 * @param {HTMLElement} el49 * @param {Object} htOption QRCode Options50 */51 export class CanvasDrawer implements IDrawingProvider { // Drawing in Canvas52 private _onMakeImage() {53 this._elImage.src = this._elCanvas.toDataURL("image/png");54 this._elImage.style.display = "block";55 this._elCanvas.style.display = "none";56 }57 constructor() {58 // Android 2.1 bug workaround59 // http://code.google.com/p/android/issues/detail?id=514160 if (this._android && this._android <= 2.1) {61 var factor = 1 / window.devicePixelRatio;62 var drawImage = CanvasRenderingContext2D.prototype.drawImage;63 CanvasRenderingContext2D.prototype.drawImage = function (image, sx, sy, sw, sh, dx, dy, dw, dh) {64 if (("nodeName" in image) && /img/i.test(image.nodeName)) {65 for (var i = arguments.length - 1; i >= 1; i--) {66 arguments[i] = arguments[i] * factor;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = new WorldWind.WorldWindow("canvasOne");2wpt.addLayer(new WorldWind.BMNGLayer());3wpt.addLayer(new WorldWind.BMNGLandsatLayer());4wpt.addLayer(new WorldWind.CoordinatesDisplayLayer(wpt));5wpt.addLayer(new WorldWind.ViewControlsLayer(wpt));6var layerManager = new LayerManager(wpt);7var image = wpt._onMakeImage();8var wpt = new WorldWind.WorldWindow("canvasOne");9wpt.addLayer(new WorldWind.BMNGLayer());10wpt.addLayer(new WorldWind.BMNGLandsatLayer());11wpt.addLayer(new WorldWind.CoordinatesDisplayLayer(wpt));12wpt.addLayer(new WorldWind.ViewControlsLayer(wpt));13var layerManager = new LayerManager(wpt);14var image = wpt._onMakeImage();

Full Screen

Using AI Code Generation

copy

Full Screen

1var win = Ti.UI.currentWindow;2var txt = Ti.UI.createTextField({3});4win.add(txt);5var aButton = Ti.UI.createButton({6});7aButton.addEventListener('click', function() {8 var aWebView = Ti.UI.createWebView({9 });10 aWebView.addEventListener('load', function() {11 txt._onMakeImage(aWebView);12 });13 win.add(aWebView);14});15win.add(aButton);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wp = wptools.page('Barack Obama');3wp.get(function(err, resp) {4 console.log(wp._onMakeImage(resp));5});6var wptools = require('wptools');7var wp = wptools.page('Barack Obama');8wp.get(function(err, resp) {9 console.log(wp._onMakeImage(resp));10});11var wptools = require('wptools');12var wp = wptools.page('Barack Obama');13wp.get(function(err, resp) {14 console.log(wp._onMakeImage(resp));15});16var wptools = require('wptools');17var wp = wptools.page('Barack Obama');18wp.get(function(err, resp) {19 console.log(wp._onMakeImage(resp));20});21var wptools = require('wptools');22var wp = wptools.page('Barack Obama');23wp.get(function(err, resp) {24 console.log(wp._onMakeImage(resp));25});26var wptools = require('wptools');27var wp = wptools.page('Barack Obama');28wp.get(function(err, resp) {29 console.log(wp._onMakeImage(resp));30});31var wptools = require('wptools');32var wp = wptools.page('Barack Obama');33wp.get(function(err, resp) {34 console.log(wp._onMakeImage(resp));35});36var wptools = require('wptools');37var wp = wptools.page('Barack Obama');38wp.get(function(err, resp) {39 console.log(wp._onMakeImage(resp));40});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2wptools._onMakeImage = function(img, options) {3 console.log('image:', img);4 console.log('options:', options);5 return img;6};7wptools.page('Barack Obama').get(function(err, page) {8 if (err) {9 console.log(err);10 } else {11 console.log(page);12 }13});14{ 15 { 16 birth_date: 'August 4, 1961 (age 53)',17 },

Full Screen

Using AI Code Generation

copy

Full Screen

1var _onMakeImage = require('./_onMakeImage.js');2var options = {3};4_onMakeImage(options, function(err, result) {5 if (err) {6 console.log(err);7 } else {8 console.log(result);9 }10});11var gm = require('gm').subClass({ imageMagick: true });12module.exports = function(options, callback) {13 gm(options.input)14 .resize(options.width, options.height, '^')15 .gravity('Center')16 .crop(options.width, options.height)17 .quality(options.quality)18 .write(options.output, function(err) {19 if (err) {20 callback(err);21 } else {22 callback(null, 'ok');23 }24 });25};

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptexturize = require('wptexturize');2var text = new wptexturize();3var text = 'This is a test';4var image = text._onMakeImage(text);5console.log(image);6var wptexturize = require('wptexturize');7var text = new wptexturize();8var text = 'This is a test';9var image = text._onMakeImage(text);10console.log(image);11var wptexturize = require('wptexturize');12var text = new wptexturize();13var text = 'This is a test';14var image = text._onMakeImage(text);15console.log(image);16var wptexturize = require('wptexturize');17var text = new wptexturize();18var text = 'This is a test';19var image = text._onMakeImage(text);20console.log(image);21var wptexturize = require('wptexturize');22var text = new wptexturize();23var text = 'This is a test';24var image = text._onMakeImage(text);25console.log(image);26var wptexturize = require('wptexturize');27var text = new wptexturize();28var text = 'This is a test';29var image = text._onMakeImage(text);30console.log(image);31var wptexturize = require('wptexturize');

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful