MCPcopy
hub / github.com/alyssaxuu/motionity / createThumbnail

Function createThumbnail

src/js/functions.js:3893–3923  ·  view source on GitHub ↗
(file, max)

Source from the content-addressed store, hash-verified

3891}
3892
3893function createThumbnail(file, max) {
3894 return new Promise(function (resolve, reject) {
3895 var reader = new FileReader();
3896 reader.onload = function (event) {
3897 var img = new Image();
3898 img.onload = function () {
3899 if (img.width > max) {
3900 var oc = document.createElement('canvas');
3901 var octx = oc.getContext('2d');
3902 oc.width = img.width;
3903 oc.height = img.height;
3904 octx.drawImage(img, 0, 0);
3905 if (img.width > img.height) {
3906 oc.height = (img.height / img.width) * max;
3907 oc.width = max;
3908 } else {
3909 oc.width = (img.width / img.height) * max;
3910 oc.height = max;
3911 }
3912 octx.drawImage(oc, 0, 0, oc.width, oc.height);
3913 octx.drawImage(img, 0, 0, oc.width, oc.height);
3914 resolve(oc.toDataURL());
3915 } else {
3916 resolve(img.src);
3917 }
3918 };
3919 img.src = event.target.result;
3920 };
3921 reader.readAsDataURL(file);
3922 });
3923}
3924
3925function dataURItoBlob(dataURI) {
3926 var byteString = atob(dataURI.split(',')[1]);

Callers 3

events.jsFile · 0.85
uploadFromURLFunction · 0.85
handleUploadFunction · 0.85

Calls 1

resolveFunction · 0.85

Tested by

no test coverage detected