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

fromDataURL() scaling issue #6

Closed
sheam opened this issue Jun 1, 2017 · 4 comments
Closed

fromDataURL() scaling issue #6

sheam opened this issue Jun 1, 2017 · 4 comments
Labels
kind: support Asking for support with something or a specific use case problem: stale Issue author has not responded scope: upstream Issue in upstream dependency solution: out-of-scope This is out of scope for this project solution: workaround available A workaround is available for this issue

Comments

@sheam
Copy link

sheam commented Jun 1, 2017

When I restore using fromDataURL(), the restored signature is about 1/4 size it was drawn in.

render the Signature Pad like this:

    public render(): JSX.Element
    {
        return (
            <div className="signature-modal-container">
                <div className="signature-modal">
                    <SignatureCanvas canvasProps={{ width: 600, height: 300 }} penColor="rgb(40,66,131)" ref={(r) => { this._signatureCanvas = r;}} />
                    <div className="signature-footer">
                        <span className="sign-above">sign above</span>
                        <div className="buttons">
                            <a onClick={this.clearClicked}>clear</a>
                            <Button bsStyle="primary" bsSize="xs" onClick={this.doneClicked}>Save</Button>
                        </div>
                    </div>
                </div>
            </div>
        );
    }

And my save method looks like this:

    @action.bound
    private doneClicked(): void
    {
        this.log('saving signature');
        this.props.delivery.SignatureData = this._signatureCanvas.getCanvas().toDataURL('image/png', 1.0);
        this._signatureCanvas.clear();
        this._signatureCanvas.fromDataURL(this.props.delivery.SignatureData);
    }

For testing purposes, I am just doing toDataURL(), clearing canvas, then restoring the contents. The restored drawing is shrunked by a factor of DPR. For example in the Chrome device emulator the iPhone 6 has a DPR of 2.0, so on save/restore the result is half ths size I drew it.

How do I handle this situation so the sigature remains the same size on save/restore on a phone?

@agilgur5
Copy link
Owner

agilgur5 commented Jan 19, 2018

this seems to be related to szimek/signature_pad#332, szimek/signature_pad#265, szimek/signature_pad#255, szimek/signature_pad#200 , szimek/signature_pad#153 , szimek/signature_pad#105 , szimek/signature_pad#89 which are related to the scaling that fromDataURL does against DPR (see also #10 (comment)). szimek/signature_pad#253 has a "solution" in there, but it would be nice to handle automatically if possible

@agilgur5
Copy link
Owner

Hi @sheam -- I just released v1.0.0-alpha.1 which now fully wraps the original signature_pad (per #17 / #20 ). The functionality to support custom options passed into fromDataURL was released in signature_pad v2.2 via szimek/signature_pad#253 and as such is now available within react-signature-canvas as well.

I think this resolves the problem, but requires manual intervention. Handling this properly / automatically would be preferred, so I'll leave this issue open as such.

@agilgur5
Copy link
Owner

I revisited this recently and I realized that I'm not sure more can even be done to handle DPR automatically. There's no way of knowing the DPR at which the dataURL was created, so I think the new options that allow you to specify it manually resolve the issue correctly.

It's possible the default DPR for fromDataURL should be something different so that the very same signature that was just created isn't resized improperly, but that would be an issue to handle upstream in signature_pad then.

Will be closing this out now.

@agilgur5 agilgur5 added help wanted problem: stale Issue author has not responded scope: upstream Issue in upstream dependency labels May 24, 2019
@nipoonp
Copy link

nipoonp commented Jan 30, 2021

I fixed this by making sure the height and the width of the sigPad is the same as when I initialized it.

sigPad.current.fromDataURL(url, { width: SIGNATURE_PAD_WIDTH, height: SIGNATURE_PAD_HEIGHT });

@agilgur5 agilgur5 changed the title fromDataURL() scaling issue fromDataURL() scaling issue Sep 17, 2022
@agilgur5 agilgur5 added kind: support Asking for support with something or a specific use case solution: out-of-scope This is out of scope for this project solution: workaround available A workaround is available for this issue labels Sep 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: support Asking for support with something or a specific use case problem: stale Issue author has not responded scope: upstream Issue in upstream dependency solution: out-of-scope This is out of scope for this project solution: workaround available A workaround is available for this issue
Projects
None yet
Development

No branches or pull requests

3 participants