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

viewportTransform affects Object.toDataURL #5063

Closed
Aubron opened this issue Jun 24, 2018 · 6 comments · Fixed by #5139
Closed

viewportTransform affects Object.toDataURL #5063

Aubron opened this issue Jun 24, 2018 · 6 comments · Fixed by #5139
Labels

Comments

@Aubron
Copy link

Aubron commented Jun 24, 2018

Version

2.3.3

Test Case

https://codepen.io/anon/pen/eKKaVr

Steps to reproduce

  1. Create an image object.
  2. Scale the viewport
  3. image.toDataURL()

Expected Behavior

a dataURL that represents the current state of the image

Actual Behavior

a dataURL that zooms (and inherently crops) the image based on the viewport transform of the canvas.

Somewhat (but not completely) related to #4602

@asturur
Copy link
Member

asturur commented Jun 24, 2018

oh i see were the problem comes from.
toDataUrl for the object has this weird bejaviour of representing the object with the angle and everything else.
But getting the viewport involved is indeed wrong.
This is an easy fix.
(i think passing a boolean to getBoundingRect) should be enough)

I think being able to choose between a dataurl representation of the object as it is on the canvas, and neutral, as a sort of object export should be given.

So i would remove viewport influence anyway and add an option ( to be better named ) withoutTransform true/false, default to false since it has been always like that.

@Aubron
Copy link
Author

Aubron commented Jun 24, 2018

All this sounds good. In my tests passing true to getBoundingRect does fix the problem. I have some other issues with photos with filters (I'm using this to extract filtered versions of images for video processing), but I'll wait til your changes are in, since the 'object export' use case is what we're going for, and then test moving the system and seeing if the issues persist.

(Currently we're doing)

if (image.filters && image.filters.length > 0 && image._filteredEl) {
          // put a version of the image to s3 that represents it with filters.
          fetch(image._filteredEl.toDataURL('png'))
}

@asturur
Copy link
Member

asturur commented Jun 24, 2018

that toDataURL from _filteredEl is a plain javascript toDataUrl and is not the fabricJS one. So for that if there is a problem, is probably not a fabricJS one.

@Aubron
Copy link
Author

Aubron commented Jun 24, 2018

Sorry, I misspoke, we've been using the _filteredEl one because of some weird inconsistencies we saw with fabric's toDataURL and filtered images.

We were using it expecting it to be an object export utility though. Hearing that it's meant to include the object's properties on the canvas may actually explain all of those away.

@asturur
Copy link
Member

asturur commented Jun 24, 2018

When i arrived, 4 years ago, it was already like that. I have no idea what was the original idea behind that method. I do think that now, a way to export it with neutral properties and another to export it as you see it, is fine and do not require any big effort

@asturur
Copy link
Member

asturur commented Aug 4, 2018

Opened a small PR, i was wondering how this should work when you target an object that is inside a group. what the withoutTransform should do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants