aaharu / gifken Goto Github PK
View Code? Open in Web Editor NEWJavaScript library that can reverse and split animated GIFs
License: MIT License
JavaScript library that can reverse and split animated GIFs
License: MIT License
Running "typescript:build" (typescript) task
src/gifken.ts(118,28): error TS2304: Cannot find name 'DataView'.
src/gifken.ts(210,30): error TS2304: Cannot find name 'DataView'.
src/gifken.ts(248,34): error TS2304: Cannot find name 'DataView'.
src/gifken.ts(272,33): error TS2304: Cannot find name 'DataView'.
src/gifken.ts(541,41): error TS2304: Cannot find name 'DataView'.
src/gifken.ts(564,40): error TS2304: Cannot find name 'DataView'.
src/gifken.ts(614,49): error TS2304: Cannot find name 'DataView'.
src/gifken.ts(655,60): error TS2304: Cannot find name 'DataView'.
src/gifken.ts(680,56): error TS2304: Cannot find name 'DataView'.
src/gifken.ts(693,67): error TS2304: Cannot find name 'DataView'.
src/gifken.ts(701,58): error TS2304: Cannot find name 'DataView'.
Warning: Task "typescript:build" failed. Use --force to continue.
Aborted due to warnings.
Hello! Thank you for your hard work!
I'm trying write a way to resize gif to 2 dimensions (original and small) with gifken and turn them into file object to send server. I wrote a code that works perfectly!
But it tooks 3-4 seconds to resize to 2 dimensions a gif that contains 102 frames.
This is my code:
var thumb = [];
var main = [];
var frame_count;
var delays;
async function thread_image_handler(){
thumb = [];
main = [];
$(".image-send").toggleClass("is-loading");
$("#fileinput").attr("disabled", "true");
var imageInput = $('#fileinput').prop('files')[0];
var imageBlob = (window.URL ? URL : webkitURL).createObjectURL(imageInput);
var i = 0;
var scaleRatio;
var desiredWidth = 75;
var widthRAW;
var heightRAW;
var finalRatio;
const xhr = new XMLHttpRequest();
xhr.open("GET", imageBlob, true);
xhr.responseType = "arraybuffer";
xhr.onload = (e) => {
const arrayBuffer = e.target["response"];
const gif = gifken.Gif.parse(arrayBuffer);
widthRAW = gif.width;
heightRAW = gif.height;
scaleRatio = desiredWidth*100/widthRAW;
finalRatio = scaleRatio/100;
frame_count = gif.frameIndex1;
const smallcanvas = document.createElement("canvas");
const maincanvas = document.createElement("canvas");
smallcanvas.width = desiredWidth;
smallcanvas.height = heightRAW*finalRatio;
maincanvas.width = widthRAW;
maincanvas.height = heightRAW;
const mainCTX = maincanvas.getContext("2d");
const smallCTX = smallcanvas.getContext("2d");
// smallCTX.clearRect(0, 0, desiredWidth, heightRAW*finalRatio);
// mainCTX.clearRect(0, 0, widthRAW, heightRAW);
Promise.all(gif.split().map((splited) => {
return new Promise((resolve, reject) => {
const img = new Image();
img.onload = () => resolve(img);
img.onerror = (e) => reject(e);
img.src = gifken.GifPresenter.writeToDataUrl(splited.writeToArrayBuffer());
})
})).then((values) => {
values.forEach(function (img) {
smallCTX.drawImage(img, 0, 0, desiredWidth, heightRAW*finalRatio);
mainCTX.drawImage(img, 0, 0);
var b64small = smallcanvas.toDataURL("image/jpeg");
var b64full = maincanvas.toDataURL("image/jpeg", 0.75);
var procMain = dataURLtoFile(b64full, "full");
var procSmall = dataURLtoFile(b64small, "thumb");
thumb.push(procMain);
main.push(procSmall);
/*
var img_full = new Image();
img_full.src = b64full;
document.getElementById("hype_swup").appendChild(img_full);
var img_small = new Image();
img_small.src = b64small;
document.getElementById("hype_swup").appendChild(img_small);
*/
i++;
if(i == frame_count){
$(".image-send").toggleClass("is-loading");
$("#fileinput").removeAttr("disabled");
$(".image-dumper").attr("src", imageBlob);
$(".image-dumper").show();
}
});
});
};
xhr.send();
}
I wanted to know if there is a better way to resize and convert each frame into a file object.
I'm tried to split some gifs using the readme example and i get this error Uncaught Error: Invalid LZW code
. When i set false
into the split()
params it work but some frame isn't complete.
For example here each two frame, the floor is missing :
import gifken from 'gifken';
var xhr = new XMLHttpRequest();
xhr.open("GET", './assets/200.gif', true);
xhr.responseType = "arraybuffer";
xhr.onload = function (e) {
var arrayBuffer = e.target["response"];
var gif = gifken.Gif.parse(arrayBuffer);
gif.split(false).forEach(function (i) {
var img = new Image();
var blob = gifken.GifPresenter.writeToBlob(i.writeToArrayBuffer());
img.src = URL.createObjectURL(blob);
document.body.appendChild(img);
});
};
xhr.send();
I'm using the 2.1.1 version of gifken.
Hi,
The GifPresenter
class is not part of the gifken exports. According to the documentation, I should be be doing:
newimg.src = gifken.GifPresenter.writeToDataUrl(newgif.writeToArrayBuffer());
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.