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

Public property for canvas element, and new CSS background image option. #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rsm-hcd
Copy link

@rsm-hcd rsm-hcd commented Oct 23, 2017

Wanted to publicly expose the canvas HTML element via the API. Added an option to use CSS to center contain the specified background image. This is intended for display purposes only, not expected to be included when the canvas is saved as an image.

…it publicly. Added another option to the setBackgroundFromDataUrl function to center contain the background image via CSS.
@tbolis
Copy link
Owner

tbolis commented Nov 16, 2017

Hi @AndcultureCode and thank you for contributing at this!

Not sure if I want to merge this since I am thinking that if you wish to put an image behind the canvas you can do that by providing an appropriate class for the SketchField

Am I missing something?

Thomas

@rsm-hcd
Copy link
Author

rsm-hcd commented Nov 16, 2017

Hi @tbolis the reason you wouldn't set a css class to accomplish this is due to the math involved when setting the background-position property since it depends on the dimensions of the image (that needs to be loaded first). The relevant code is:

img.onload = () => {
     const sizeX = img.width <= img.height ? "auto" : "100%";
     const sizeY = img.width > img.height ? "auto" : "100%";
     this._canvas.style.background = `url(${dataUrl})`;
     this._canvas.style.backgroundSize = `${sizeX} ${sizeY}`;
     this._canvas.style.backgroundRepeat = "no-repeat";
     this._canvas.style.backgroundPosition = "center";
 };

@tbolis
Copy link
Owner

tbolis commented Nov 23, 2017

ok sounds fair, I will think about it a bit more on how I can support you on this
cheers

@karlvr
Copy link
Contributor

karlvr commented Feb 2, 2019

The Fabric StaticCanvas has a getElement() method which returns the underlying canvas. Would exposing getElement() be more appropriate in react-sketch?

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

Successfully merging this pull request may close these issues.

None yet

4 participants