I'm using the https://github.com/antimatter15/jsgif and I was wondering if anyone knows why this happens.
I now only get this as my return "data:image/gif;base64,R0lGODlhOw=="
This is my code
var GetCanvas = document.getElementById("GifHere");
var contextOfCanvas = GetCanvas.getContext("2d");
var encoder = new GIFEncoder();
encoder.setRepeat(0);
encoder.setDelay(1000);
GetCanvas.width = 1600;
GetCanvas.height = 800;
encoder.setSize(1600,800);
contextOfCanvas.fillStyle = "rgb(255,255,255)";
contextOfCanvas.fillRect(0,0,GetCanvas.width, GetCanvas.height);
encoder.start();
console.log(encoder.start());
var GifLength = $(".LayerImages").length + 1;
StartingLength = GifLength;
StartPosition = 1;
loadGifImages(encoder,GifLength);
var imageOf = GetCanvas.toDataURL("image/"+SelectedValue);
var FileType = SelectedValue;
var imageData = imageOf;
var RemoveLength = "data:image/png;base64,";
var stringLength = parseInt(imageData.length) - parseInt(RemoveLength.length);
var sizeInBytes = 4 * Math.ceil((stringLength / 3))*0.5624896334383812;
var FileSize = sizeInBytes / 1024;
This is my loadGifImages function
function loadGifImages(encoder,length){
var GetCanvas = document.getElementById("GifHere");
var contextOfCanvas = GetCanvas.getContext("2d");
var Canvas = document.getElementById("Can"+StartPosition);
console.log(Canvas);
var CanvasContext = Canvas.getContext("2d");
var image0 = new Image();
var imageData = CanvasContext.getImageData(0,0,1600,800);
encoder.addFrame(imageData,true);
console.log(imageData);
StartPosition++;
length--;
if(length == 1 && StartPosition == StartingLength){
isGifDone = true;
encoder.finish();
var gif = encoder.stream().getData();
var url = 'data:image/gif;base64,'+encode64(gif);
console.log(url);
/* document.getElementById("ImageSaved").src = 'data:image/gif;base64,'+encode64(encoder.stream().getData());
*/ }else{
loadGifImages(encoder,length);
}
Everything seems to work but it seems that something inside that library is giving the chrome extension an error. I tried adding the content_security_policy to my manifest.json but it doesn't seem to be working with that. This is my manifest.json file
{
"name": "Better Photo Editor",
"version": "0.0.0.1",
"content_security_policy":"script-src 'self' https://apis.google.com; object-src 'self'",
"description": "Better Photo Editor",
"content_scripts": [
{
"matches": ["<all_urls>"],
"css": ["CSS/style.css"]
}
],
"browser_action": {
"default_icon": "Images/Drawing.png",
"default_title": "",
"default_popup": "Home.html"
},
"permissions": ["<all_urls>","http://*/","https://*/","activeTab","unlimitedStorage"],
"manifest_version": 2
}
Edit: I think it has something to do with the writebyte in the GIFEncoder.js but I am unsure. I can't trace it back to anything, though I am still trying. If anyone can help, I would appreciate it!! I don't have any inline javascript in any of the html pages. I know this will probably be asked, making it clear now that it isn't that.