[英]How do I check if a pixel is empty?
我正在获取.gif
。 我需要知道content-length是否为0
或是否为1×1像素。 有没有办法通过JavaScript对图像执行此操作?
您可以使用Image
对象加载和检查尺寸,然后再将其加载到DOM。
var img = new Image() img.src ='http://lorempixel.com//1/1'; img.addEventListener("load", function() { console.log(img.naturalWidth) console.log(img.naturalHeight) }, false); //outputs 1 1
这应该为您做。
$('#image').change(function() { var img = new Image(); img.onload = function(){ $('#height').html(img.height); $('#width').html(img.width); }; img.src = $(this).val(); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <label>Image URL: <input type="text" id="image" /></label> <h1>Width: <span id="width"></span></h1> <h1>Height: <span id="height"></span></h1>
如何查看gifuct-js https://github.com/matt-way/gifuct-js
这是js中的gif解析器。
decompressFrames(buildPatch)函数的结果返回所有GIF图像帧及其元数据的数组。
您还可以获取像素数据
像素数据存储为每个像素的索引列表。 这些都指向colorTable数组中的一个值,该值包含每个像素应绘制的颜色。 gif的每一帧可能不是完整大小,而是需要在特定位置绘制的补丁。 处置类型定义了应如何在gif画布上绘制该补丁。 在大多数情况下,该值为1,表示应该在现有的gif画布上简单绘制gif框架,而不更改框架补丁尺寸之外的任何像素。 在这里可以了解更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.