Skip to content

Commit

Permalink
0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
alselawi committed Mar 29, 2023
1 parent 3222e59 commit 8595b0f
Show file tree
Hide file tree
Showing 25 changed files with 6,303 additions and 2,327 deletions.
42 changes: 21 additions & 21 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License

Copyright (c) 2020 Alex Corvi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License

Copyright (c) 2020 Alex Corvi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
116 changes: 58 additions & 58 deletions assets/demo-sample-files.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
function loadHEIC(url) {
return new Promise((resolve, reject) => {
fetch(url)
.then(function (x) {
return x.blob();
})
.then(function (x) {
console.log("working on", x);
return heic2any({ blob: x, toType: "image/gif" });
})
.then(function (x) {
var url = URL.createObjectURL(x);
document.getElementById("demo-sample-files").innerHTML =
document.getElementById("demo-sample-files").innerHTML +
'<a target="_blank" href="' +
url +
'"><img src="' +
url +
'"></a>';
resolve();
})
.catch(function (e) {
reject(e);
});
});
}

const files = [];

for (let i = 1; i < 16; i++) {
files.push("./demo/" + i + ".heic");
}

/*
* serial executes Promises sequentially.
* @param {funcs} An array of funcs that return promises.
* @example
* const urls = ['/url1', '/url2', '/url3']
* serial(urls.map(url => () => $.ajax(url)))
* .then(console.log.bind(console))
*/
const serial = (funcs) =>
funcs.reduce(
(promise, func) =>
promise.then((result) =>
func().then(Array.prototype.concat.bind(result))
),
Promise.resolve([])
);

// next convert each item to a function that returns a promise
const funcs = files.map((file) => () => loadHEIC(file));

serial(funcs)
.then(() => {
document.getElementById("loading").innerHTML = "";
})
.catch((e) => console.log(e));
function loadHEIC(url) {
return new Promise((resolve, reject) => {
fetch(url)
.then(function (x) {
return x.blob();
})
.then(function (x) {
console.log("working on", x);
return heic2any({ blob: x, toType: "image/gif" });
})
.then(function (x) {
var url = URL.createObjectURL(x);
document.getElementById("demo-sample-files").innerHTML =
document.getElementById("demo-sample-files").innerHTML +
'<a target="_blank" href="' +
url +
'"><img src="' +
url +
'"></a>';
resolve();
})
.catch(function (e) {
reject(e);
});
});
}

const files = [];

for (let i = 1; i < 16; i++) {
files.push("./demo/" + i + ".heic");
}

/*
* serial executes Promises sequentially.
* @param {funcs} An array of funcs that return promises.
* @example
* const urls = ['/url1', '/url2', '/url3']
* serial(urls.map(url => () => $.ajax(url)))
* .then(console.log.bind(console))
*/
const serial = (funcs) =>
funcs.reduce(
(promise, func) =>
promise.then((result) =>
func().then(Array.prototype.concat.bind(result))
),
Promise.resolve([])
);

// next convert each item to a function that returns a promise
const funcs = files.map((file) => () => loadHEIC(file));

serial(funcs)
.then(() => {
document.getElementById("loading").innerHTML = "";
})
.catch((e) => console.log(e));
66 changes: 33 additions & 33 deletions assets/demo-user-file.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
document.getElementById("user-file").addEventListener("change", function (ev) {
document.getElementById("error-on-try").innerHTML = "";
document.getElementById("error-on-try").style.display = "none";
var blob = ev.target.files[0];
heic2any({
blob: blob,
toType: "image/gif",
})
.then(function (resultBlob) {
saveFile(resultBlob, blob.name + ".gif");
})
.catch(function (x) {
document.getElementById("error-on-try").style.display = "block";
document.getElementById("error-on-try").innerHTML =
"Error code: <code>" + x.code + "</code> " + x.message;
});
});
function saveFile(blob, filename) {
if (window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob, filename);
} else {
var a = document.createElement("a");
document.body.appendChild(a);
var url = window.URL.createObjectURL(blob);
a.href = url;
a.download = filename;
a.click();
setTimeout(function () {
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
}, 0);
}
}
document.getElementById("user-file").addEventListener("change", function (ev) {
document.getElementById("error-on-try").innerHTML = "";
document.getElementById("error-on-try").style.display = "none";
var blob = ev.target.files[0];
heic2any({
blob: blob,
toType: "image/gif",
})
.then(function (resultBlob) {
saveFile(resultBlob, blob.name + ".gif");
})
.catch(function (x) {
document.getElementById("error-on-try").style.display = "block";
document.getElementById("error-on-try").innerHTML =
"Error code: <code>" + x.code + "</code> " + x.message;
});
});
function saveFile(blob, filename) {
if (window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob, filename);
} else {
var a = document.createElement("a");
document.body.appendChild(a);
var url = window.URL.createObjectURL(blob);
a.href = url;
a.download = filename;
a.click();
setTimeout(function () {
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
}, 0);
}
}
Loading

0 comments on commit 8595b0f

Please sign in to comment.