mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-03 22:07:30 +09:00
import FIREFOX_52_6_0esr_RELEASE from mozilla-esr52 hg repo
This commit is contained in:
commit
dcd9973243
150858 changed files with 23884658 additions and 0 deletions
68
dom/html/reftests/toblob-todataurl/blob.js
Normal file
68
dom/html/reftests/toblob-todataurl/blob.js
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
function init() {
|
||||
function end() {
|
||||
document.documentElement.className = '';
|
||||
}
|
||||
|
||||
function next() {
|
||||
compressAndDisplay(original, end);
|
||||
}
|
||||
|
||||
var original = getImageFromDataUrl(sample);
|
||||
setImgLoadListener(original, next);
|
||||
}
|
||||
|
||||
function compressAndDisplay(image, next) {
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.width = image.naturalWidth;
|
||||
canvas.height = image.naturalHeight;
|
||||
var ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(image, 0, 0);
|
||||
|
||||
function gotBlob(blob) {
|
||||
var img = getImageFromBlob(blob);
|
||||
setImgLoadListener(img, next);
|
||||
document.body.appendChild(img);
|
||||
}
|
||||
|
||||
// I want to test passing 'undefined' as quality as well
|
||||
if ('quality' in window) {
|
||||
canvas.toBlob(gotBlob, 'image/jpeg', quality);
|
||||
} else {
|
||||
canvas.toBlob(gotBlob, 'image/jpeg');
|
||||
}
|
||||
}
|
||||
|
||||
function setImgLoadListener(img, func) {
|
||||
if (img.complete) {
|
||||
func.call(img, { target: img});
|
||||
} else {
|
||||
img.addEventListener('load', func);
|
||||
}
|
||||
}
|
||||
|
||||
function naturalDimensionsHandler(e) {
|
||||
var img = e.target;
|
||||
img.width = img.naturalWidth;
|
||||
img.height = img.naturalHeight;
|
||||
}
|
||||
|
||||
function getImageFromBlob(blob) {
|
||||
var img = document.createElement('img');
|
||||
img.src = window.URL.createObjectURL(blob);
|
||||
setImgLoadListener(img, naturalDimensionsHandler);
|
||||
setImgLoadListener(img, function(e) {
|
||||
window.URL.revokeObjectURL(e.target.src);
|
||||
});
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
function getImageFromDataUrl(url) {
|
||||
var img = document.createElement('img');
|
||||
img.src = url;
|
||||
setImgLoadListener(img, naturalDimensionsHandler);
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
init();
|
||||
Loading…
Add table
Add a link
Reference in a new issue