使用 javascript 获取 GIF 图的帧数,如果帧数过大,则不让传到服务器
这里是使用一个插件: github地址为: https://github.com/buzzfeed/libgif-js
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<style type="text/css">
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
</style>
</head>
<body>
<input type="file" name="file" id="file" value="" />
</body>
<script type="text/javascript" src="js/libgif.js"></script>
<script type="text/javascript">
document.getElementById("file").onchange = function(e){
var filse = this.files;
sendFile(filse[0]);
}
function sendFile(file){
var reader =new FileReader();
reader.readAsDataURL(file);
reader.onload=function(e){
var div = document.createElement("div");
var img = document.createElement("img");
div.appendChild(img);
img.src = this.result;
img.onload = function(){
var rub = new SuperGif({ gif: img} );
rub.load(function(){
console.log(rub.get_length());
});
}
}
}
</script>
</html>