Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to run in the command line? #1

Closed
thoppe opened this issue Apr 30, 2020 · 2 comments
Closed

Possible to run in the command line? #1

thoppe opened this issue Apr 30, 2020 · 2 comments

Comments

@thoppe
Copy link

thoppe commented Apr 30, 2020

This is super cool and I'm excited that you open-sourced it! I'm coming from a python background and I'd like to use the output somehow as a starting point for other programs. Is there a way to call this from the command line so I can script it? I tried using nodejs, but I got stuck trying to require the library properly.

Feel free to close it as this may be out of scope for supporting this use case.

const ATCQ = require('./atcq.js');
var getPixels = require("get-pixels");

var f_image = "./sample_image_small.jpg";

var pixels = getPixels(f_image, function(err, pixels) {
    if(err) {
	console.log("Bad image path")
	return;
    }
    console.log("got pixels", pixels)    
    
    const palette = ATCQ.quantizeSync(pixels, {
	maxColors: 32
    }); 
    console.log(palette);    
});

Which gave:

nodejs demo.js
got pixels View3dbuffer {
  data: <Buffer fe f9 f1 ff fe f9 ef ff fe f9 ef ff fc fa ed ff fd fb ee ff fe fc f1 ff fe fc f3 ff fd fb f2 ff fb fb ef ff fb fb ef ff fb fb f1 ff fb fb f1 ff fb fb ... >,
  shape: [ 200, 284, 4 ],
  stride: [ 4, 800, 1 ],
  offset: 0 }
/home/hoppeta/projects/palette/atcq/atcq.js:16
  atcq.quantize();
       ^

TypeError: atcq.quantize is not a function
    at Function.quantizeSync (/home/hoppeta/projects/palette/atcq/atcq.js:16:8)
    at /home/hoppeta/projects/palette/atcq/demo.js:19:26
    at handleJPEG (/home/hoppeta/projects/palette/atcq/node_modules/get-pixels/node-pixels.js:44:3)
    at doParse (/home/hoppeta/projects/palette/atcq/node_modules/get-pixels/node-pixels.js:114:7)
    at /home/hoppeta/projects/palette/atcq/node_modules/get-pixels/node-pixels.js:190:7
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)
@mattdesl
Copy link
Owner

mattdesl commented May 1, 2020

Thanks for testing! Actually there was a typo in my code, I've just fixed it in atcq@1.0.3.

You can also see demo/extract.js which runs on the command-line with Node.js.

@thoppe
Copy link
Author

thoppe commented May 1, 2020

Thanks @mattdesl, it works perfectly now! For anyone else searching for this in the future, here is the expected output for atcq@1.0.3 using the supplied baboon image and const maxColors = 32; const targetColors = 5;

Progress: 31%
Progress: 58%
Progress: 83%
Progress: 100%
Finished quantizing:
[ { color: '#eb5236', weight: 0.35426846511505555 },
  { color: '#98c2e1', weight: 0.34554147457861195 },
  { color: '#ce8980', weight: 0.10969570621543237 },
  { color: '#38322e', weight: 0.10299427188488527 },
  { color: '#4a5e49', weight: 0.08750008220601485 } ]

@thoppe thoppe closed this as completed May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants