3

Is it possible to get pixels array in nodeJs without canvas or smth like that? Suppose I have image path. I tried several libraries but all of them need canvas or there's error with 'SOI not found'.

For example that:

var getPixels = require('get-image-pixels')
var data = getPixels('0.jpg');

Unhandled rejection Error: SOI not found

Or that:

var image = require('get-image-data')

image('0.jpg', function(error, info) {
  var height = info.height
  var width = info.width
  var data = info.data

  for (var i = 0, l = data.length; i < l; i += 4) {
    var red = data[i]
    var green = data[i + 1]
    var blue = data[i + 2]
    var alpha = data[i + 3]
  }
})

module.js:557 throw err;

Error: Cannot find module 'canvas'

Alex Johnson
  • 173
  • 3
  • 15
  • Maybe [get-pixels](https://github.com/scijs/get-pixels) library is what you're looking for? It returns an *N*-Dimensional Array though. Alternatively if you only need to perform this on JPEGs, you could use [jpeg-js](https://github.com/eugeneware/jpeg-js) directly, which returns a `Uint8Array` and internally performs clamping. – Sven Mar 20 '18 at 19:14
  • Both of these libs show "SOI not found" error. And I don't know even what is SOI there – Alex Johnson Mar 21 '18 at 03:15
  • But it depends on file actually!) some files are OK but some return such error – Alex Johnson Mar 21 '18 at 03:40
  • 1
    SOI means "Start of image", and when in doubt you can always look through [the source](https://github.com/eugeneware/jpeg-js/blob/master/lib/decoder.js#L598) to find out :) But I must say that's an unnecessarily cryptic error message. – Sven Mar 21 '18 at 05:51

0 Answers0