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

setSrc in the third param doesnt apply width and height #4890

Closed
salomonsanz opened this issue Apr 6, 2018 · 3 comments
Closed

setSrc in the third param doesnt apply width and height #4890

salomonsanz opened this issue Apr 6, 2018 · 3 comments
Labels
stale Issue marked as stale by the stale bot

Comments

@salomonsanz
Copy link

salomonsanz commented Apr 6, 2018

Version

2.2.3

Test Case

http://jsfiddle.net/Da7SP/1434/

Steps to reproduce

in the setSrc method, in the third param specify a width and height values

Expected Behavior

The loaded image using "setSrc" should have the specified width and height

Actual Behavior

It is forced to have the original element width and height and the size only can be changed using the scaleX and scaleY params, forzing to use again a fix function in the setSrc callback (used up to this point and that I was hoping this new version would fix). The behaviour that setSrc used to have in the v1.* was perfect.

fabric.Image.prototype.fixFabricV2Scale = function() 
{
       let img = this.getElement();
       var real_width = this.width * this.scaleX;
       var real_height = this.height * this.scaleY;

       this.set({
               width: img.naturalWidth,
               height: img.naturalHeight,
               scaleX: real_width / img.naturalWidth,
               scaleY: real_height / img.naturalHeight
       });            
}
@asturur
Copy link
Member

asturur commented Apr 6, 2018

Well to be honest i did not think this as a part of the api.
But i see your point.

I thought that setSrc would have been called just to change the image element and that it was the right thing to set original width and height.

This is a use case i did not think about.
You can set width and height with just passing options down to setWidthAndHeight, but this will not change the v2 behaviour that is about cropping an image and not scaling it down.

If you want to open a PR for it please do it, or i'll do as soon as i can.

@scriptspry
Copy link
Contributor

It's probably my mistake not tagging @asturur in the comment i made few days ago.

#4877 (comment)

I think that's what's causing this issue. Working fiddle.

@stale
Copy link

stale bot commented Jan 26, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issue marked as stale by the stale bot label Jan 26, 2020
@stale stale bot closed this as completed Feb 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Issue marked as stale by the stale bot
Projects
None yet
Development

No branches or pull requests

3 participants