从APNG规范来看,APNG似乎是PNG,它们在“额外的”块中描述第一个帧之后的帧。因此,在Javascript中轻松地创建APNG似乎是可行的,只需合成PNG报头并将dataURI附加到它们。然而,这并不顺利。
function compileAPNG (frames, width, height, fps) {
var fromCharCode = String.fromCharCode;
var CRC = fromCharCode(0, 0, 0, 0);
var pngData = fromCharCode(137, 80, 78, 71, 13, 10, 26, 10);
pngData += fromCharCode(0, 0, 0, 13) + "IHDR" + convertIntToBytes(width) + convertIntToBytes(height) + fromCharCode(0, 0, 0, 0, 0) + CRC
pngData += fromCharCode(0, 0, 0, 8) + "acTL" + convertIntToBytes(frames.length) + fromCharCode(0, 0, 0, 0) + CRC;
pngData += fromCharCode(0, 0, 0, 25) + "fcTL" + fromCharCode(0, 0, 0, 0) + convertIntToBytes(width) + convertIntToBytes(height);
pngData += fromCharCode(0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + convertShortToBytes(fps) + fromCharCode(1, 0) + CRC;
pngData += convertIntToBytes(frames[0].toDataURL().length) + "IDAT" + frames[0].toDataURL() + CRC;
for (index = 1; index < frames.length; index++) {
pngData += fromCharCode(0, 0, 0, 25) + "fcTL" + fromCharCode(0, 0, 0, 0) + convertIntToBytes(width) + convertIntToBytes(height);
pngData += fromCharCode(0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + convertShortToBytes(fps) + fromCharCode(1, 0) + CRC;
pngData += convertIntToBytes(frames[index].toDataURL().length) + "fdAT" + convertIntToBytes(index) + frames[index].toDataURL() + CRC;
}
pngData += fromCharCode(0, 0, 0, 0) + "IEND" + CRC;
window.open("data:image/png;base64," + btoa(pngData));
}
CRC计算的计算开销很大,所以我试图通过将它们全部设置为0来欺骗它们。这就是火狐不接受dataURI作为镜像的原因吗?
发布于 2015-08-03 03:22:49
您的文件被Firefox拒绝的原因至少有以下几个:
https://stackoverflow.com/questions/31777569
复制