Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

save-pixels

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

save-pixels - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

3

package.json
{
"name": "save-pixels",
"version": "2.1.0",
"version": "2.2.0",
"description": "Saves an ndarray as an image to a file",

@@ -12,2 +12,3 @@ "main": "save-pixels.js",

"contentstream": "^1.0.0",
"gif-encoder": "~0.4.1",
"jpeg-js": "0.0.4",

@@ -14,0 +15,0 @@ "pngjs": "~0.4.0-alpha",

"use strict"
var ContentStream = require("contentstream")
var GifEncoder = require("gif-encoder")
var jpegJs = require("jpeg-js")

@@ -8,5 +9,14 @@ var PNG = require("pngjs").PNG

function handleData(array, data) {
function handleData(array, data, frame) {
var i, j, ptr = 0, c
if(array.shape.length === 3) {
if(array.shape.length === 4) {
for(j=0; j<array.shape[2]; ++j) {
for(i=0; i<array.shape[1]; ++i) {
data[ptr++] = array.get(frame,i,j,0)>>>0
data[ptr++] = array.get(frame,i,j,1)>>>0
data[ptr++] = array.get(frame,i,j,2)>>>0
data[ptr++] = array.get(frame,i,j,3)>>>0
}
}
} else if(array.shape.length === 3) {
if(array.shape[2] === 3) {

@@ -85,2 +95,17 @@ for(j=0; j<array.shape[1]; ++j) {

case "GIF":
case ".GIF":
var frames = array.shape.length === 4 ? array.shape[0] : 1
var width = array.shape.length === 4 ? array.shape[1] : array.shape[0]
var height = array.shape.length === 4 ? array.shape[2] : array.shape[1]
var data = new Buffer(width * height * 4)
var gif = new GifEncoder(width, height)
gif.writeHeader()
for (var i = 0; i < frames; i++) {
data = handleData(array, data, i)
gif.addFrame(data)
}
gif.finish()
return gif
case "PNG":

@@ -87,0 +112,0 @@ case ".PNG":

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc