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

getPixelColor script not actually cropping before identify #226

Open
felipewil opened this issue Jun 13, 2019 · 0 comments
Open

getPixelColor script not actually cropping before identify #226

felipewil opened this issue Jun 13, 2019 · 0 comments

Comments

@felipewil
Copy link

From getPixelColor.js file:

...
gm(imagePath)
.crop(x, y)
.identify('%[hex:s]', (error, imageMagickColor) => { ... })
...

So, the code above is supposed to crop the given image and then execute the identify. But actually only the identify command is getting called.

Testing a bit and looking into the gm source, it seems that the crop function adds some params to an _out property but not execute it until write, stream or toBuffer is called.

To test it easier, I extracted those lines into a separate file. Here is what I tried:

const result = gm('some_image.png').crop(1, 1).identify((err, response) => {
  console.log(response);
});

With debug on, only the following command is executed:
gm identify "-ping" "-verbose" "some_image.png"

The result var value is:

gm {
  ...
  _out: [ '-crop', '1x1+0+0' ],
  _subCommand: 'convert',
  source: 'some_image.png',
  ...
}

The crop command is still there, not executed.
And the response from the identify:

{
  Format: 'PNG (Portable Network Graphics)',
  format: 'PNG',
  'Mime type': 'image/png',
  Class: 'DirectClass',
  Geometry: '2208x2208+0+0',
  size: { width: 2208, height: 2208 },
  ...
}

2208x2208 is the actual size of the image I used.
Now, if I call toBuffer before identify, like:

const result = gm('some_image.png').crop(1, 1).toBuffer((err, buffer) => {
  gm(buffer).identify((err, response) => {
    console.log(response);
  });
});

Then both these command are executed:

gm convert "some_image.png" "-crop" "1x1+0+0" "-"
gm identify "-ping" "-verbose" "-"

Result var value:

gm {
  ...
  _out: [],
  _subCommand: 'convert',
  source: 'some_image.png',
  ...
}

Now _out is empty, the crop was executed.
And the identify response is:

{
  'Base filename': '-',
  Format: 'PNG (Portable Network Graphics)',
  format: 'PNG',
  'Mime type': 'image/png',
  Class: 'PseudoClass',
  Geometry: '1x1+0+0',
  size: { width: 1, height: 1 }
  ...
}

Applying the change too getPixelColor.js it correctly crops before identifying.

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

1 participant