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

Reset width and height for an image when swapping src #4877

Merged
merged 4 commits into from
Apr 1, 2018

Conversation

asturur
Copy link
Member

@asturur asturur commented Mar 31, 2018

close #4733

needs tests

@asturur asturur merged commit 1e5c64f into master Apr 1, 2018
@@ -369,6 +369,7 @@
setSrc: function(src, callback, options) {
fabric.util.loadImage(src, function(img) {
this.setElement(img, options);
this._setWidthHeight();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umm... did you forget to pass options to _setWidthHeight or is this intentional? Just wondering.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scriptspry Great question. I just tried using setSrc with width and height specified in options, and the provided options were not set. I ended up needing to use loadImage directly, which shouldn't be necessary. I vote for options to be passed in to this._setWidthHeight() or better, don't call _setWidthHeight at all and let setElement take care of it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was some reason this was done.
I'll try to recover it.
It could be that setSrc will intentionally reset the image from scratch, and if you need to set it with different widht/height/scropX/cropY you do that in the callback.
What would be wrong with this approach?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asturur Hi, nothing wrong with the approach of changing the width and height in the callback, it's just when I looked at the fabric source code I thought for sure not passing options along was a bug. I almost created a PR to fix it, then I noticed this comment and wanted to follow up.

@asturur asturur mentioned this pull request Apr 2, 2018
@asturur asturur deleted the reset-width-height branch April 25, 2018 08:42
@asturur asturur mentioned this pull request May 8, 2018
thiagocunha pushed a commit to thiagocunha/fabric.js that referenced this pull request Nov 18, 2019
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.

Image setSrc, setElement and width/height value
3 participants