Skip to content

Pixel-based color sampling for the Eyedropper tool #545

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

Closed
Keavon opened this issue Feb 12, 2022 · 8 comments · Fixed by #801
Closed

Pixel-based color sampling for the Eyedropper tool #545

Keavon opened this issue Feb 12, 2022 · 8 comments · Fixed by #801
Assignees
Labels
Good First Issue Good for newcomers Web Involves web programming (TypeScript, Svelte, CSS)
Milestone

Comments

@Keavon
Copy link
Member

Keavon commented Feb 12, 2022

Since there's no way to obtain the color of a pixel from a rendered web page, the Eyedropper tool currently just grabs the fill color of the shape that's clicked on. It doesn't know if you are clicking on the stroke of a shape instead. Or if you are clicking on somewhere along a gradient where you'd expect to pick the interpolated color. (For gradients, we're just using the color on one end of the gradient.) Picking the exact color of the pixel under the mouse cursor would be a more useful behavior. Given the above-mentioned issue, there are two approaches with pros and cons:

  • Use the EyeDropper API which is supported on Chromium-based browsers.
    Pro: works even outside the viewport or web browser entirely
    Con: limited browser support (no Firefox and Safari)
  • Rasterize the document and render it to an off-screen canvas then sample the corresponding pixel colors from that, using the same code for exporting artwork as PNG/JPG (see Add the File > Export dialog and PNG/JPG downloading #629). It'd have to re-render every time the canvas changes, in case the user pans/scrolls/zooms while picking colors. Be careful of possible DPI scaling-related gotchas. This can be done by rasterizing the canvas with 1x1 dimensions and just taking the color of that one pixel.
    Pro: works in all browsers
    Con: possibly worse performance

The second option is probably a better long-term solution.

@Keavon Keavon added Feature Good First Issue Good for newcomers Web Involves web programming (TypeScript, Svelte, CSS) labels Feb 12, 2022
@Keavon Keavon added this to the Sprint 14 (upcoming) milestone Feb 12, 2022
@Keavon Keavon changed the title Use EyeDropper API for color selection on supported browsers Pixel-based color sampling for the Eyedropper tool May 10, 2022
@Keavon Keavon modified the milestones: Sprint 14, Sprint 15 (ongoing) May 14, 2022
@jackiechen73
Copy link
Contributor

@Keavon Hey I'm interested in working on this!

@Keavon
Copy link
Member Author

Keavon commented Jun 5, 2022

Great! I recommend the more robust approach of rasterizing the artwork, as described in the second bullet point. Although admittedly that'll be a little more difficult, but it's the better solution. Feel free to ask how to get started on this and we can talk through it on Discord.

@Keavon
Copy link
Member Author

Keavon commented Jun 19, 2022

@jackiechen73 just checking if this is still in progress. No worries if not, I can always move it back to the Up For Grabs list so someone else can take it on.

@jackiechen73
Copy link
Contributor

@Keavon Still working on it! Got caught up with school and midterms for a bit but looking to finish this up soon

@mfish33
Copy link
Contributor

mfish33 commented Jun 22, 2022

@Keavon just came across this it seems promising. https://github.com/canvg/canvg. Was going to start working on this but it seems like @jackiechen73 has it covered.

@Keavon
Copy link
Member Author

Keavon commented Jun 22, 2022

@Keavon just came across this it seems promising. https://github.com/canvg/canvg. Was going to start working on this but it seems like @jackiechen73 has it covered.

No need for a dependency, we can use the canvas API to render the SVG string from a blob URL as an image drawn to the canvas. It supports SVG as one of the file types. That's how we already save JPG and PNG from the export dialog.

@jackiechen73 jackiechen73 removed their assignment Jun 27, 2022
@jackiechen73
Copy link
Contributor

@Keavon I think I'm going to drop this ticket -- tried implementing the second solution without much success :(

@Keavon
Copy link
Member Author

Keavon commented Jun 27, 2022

@Keavon I think I'm going to drop this ticket -- tried implementing the second solution without much success :(

That's fine, no worries. Thanks for the update. I'll move this back to the Available column so somebody else can potentially pick it up if they're interested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue Good for newcomers Web Involves web programming (TypeScript, Svelte, CSS)
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants