bamlab / bamlab/generator-rn-toolbox

getPixelColor script not actually cropping before identify

Open
#226 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.2k
Forks
116
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in getPixelColor.js and inspect how the gm image chain calls identify after crop. Reproduce the reported command with a sample image, then verify that the identify response reports the cropped dimensions rather than the original image size. Done means getPixelColor.js crops the image before identifying its pixel color.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.