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

Load image from JSON made in 1.7 into 2.0 not the same #4235

Closed
blobinabottle opened this issue Aug 22, 2017 · 35 comments
Closed

Load image from JSON made in 1.7 into 2.0 not the same #4235

blobinabottle opened this issue Aug 22, 2017 · 35 comments

Comments

@blobinabottle
Copy link
Contributor

blobinabottle commented Aug 22, 2017

Version

2.0b6

Test Case

http://jsfiddle.net/fmgXt/849/ Fabric 2.0
http://jsfiddle.net/fmgXt/848/ Fabric 1.7.15

Steps to reproduce

load a JSON made in Fabric 1.7 in Fabric 2.0

Expected Behavior

Images should load the same way.
I guess it's because of the change in width/height behavior?

Actual Behavior

The image in Fabric 2.0 is cropped and bigger. Can figure out a way to make it similar to Fabric 1.7.15

@blobinabottle blobinabottle changed the title Load image from JSON: not coherent in Fabric 2.0 b6 Load image from JSON made in 1.7 into 2.0 not the same Aug 22, 2017
@asturur
Copy link
Member

asturur commented Aug 22, 2017

good point.
The changes in width/height influence the way the image is displayed in a different way.

for me now is a mess going in the json, could you eliminate what is not image from your json fiddle?

Also do you think you can explain me why / how you ended up modifying the image width/height?

@blobinabottle
Copy link
Contributor Author

Cleaner version of json here:
fab 1.7.15 http://jsfiddle.net/fmgXt/848/
fab 2.0b6 http://jsfiddle.net/fmgXt/851/
And you're right, I think we made a mistake on our side, in some cases we change the widht/height by setting all the properties at once with set{height, width, etc} (it's when user upload big images we resized them this way... so it's our mistake).

@asturur
Copy link
Member

asturur commented Aug 22, 2017

i think anyway flagging the new json of fabricjs as version 2 must be done.
So that everyone can see if the JSON loading back has a version, and if not can apply some migration scripts.
Breaking changes in json are are, the one for text are handled automatically fabric and are very simple.

In your case is just needed to reset image width/height reading from element and apply a scale factor. let me study the thing better but i think is fairly simple.

@jilster
Copy link

jilster commented Aug 23, 2017

I encountered the same thing. In my application it is very important that all objects have exactly the same strokeWidth and shadowOffset. Because those are influenced by the scale of the object, i initially made a simple function that kept the scaleX and scaleY at 1 and changed the dimensions instead doing something like:

object.width = object.width * object.scaleX;
object.height = object.height * object.scaleY;
object.scaleX = 1;
object.scaleY = 1;

This kept the objects nice and uniform, but since version 2, the images were not displayed correctly. I fixed that using another function that reapplies scale to images, and uses it to scale the strokeWidth and shadowOffset accordingly. To do this i used the image's natural dimensions. Something like:

object.width = imageNaturalWidth;
object.height = imageNaturalHeight;
object.scaleX = object.width / imageNaturalWidth;
object.scaleY = object.height / imageNaturalHeight;
object.shadow.offsetX = object.shadow.offsetX / object.scaleX;
object.shadow.offsetY = object.shadow.offsetY / object.scaleY;
object.strokeWidth = object.strokeWidth / object.scaleX; 
// strokeWidth needs improvement, maybe scaleX != scaleY

I am doing this for every image now, i was still contemplating how to use some kind of indicator that this is not necessary. A version flag in the json would be perfect for this

@asturur
Copy link
Member

asturur commented Aug 23, 2017

A json version is necessary.

For stroke purposes you can get a better effect if you scale the canvas before stroking.
Where the image has the code for making the stroke, just set the scale to (1/this.scaleX, 1/this.scaleY) before stroking.

Changing the way images uses width/height is the only way to introduce cropping. I could have introduced cropWidth and cropHeight, but sincerly i do not like that you can scale an image with both width/height and scaleX/scaleY, is just confusing.

@jilster
Copy link

jilster commented Aug 23, 2017

I agree, this is the most logical way to scale and crop. Thanks for the advice on the stroke!

@asturur
Copy link
Member

asturur commented Aug 25, 2017

just to say that i ll try to push the version in json later today and post a snippet to convert the image json so that you are not blocked to move on.

@blobinabottle
Copy link
Contributor Author

Awesome. I agree too, this new way is logical to me. And we'll be able to crop! that's insanely cool :D

@asturur
Copy link
Member

asturur commented Aug 25, 2017

missed the timeline. did not find 20 minutes, maybe tomorrow after travelling!

@asturur
Copy link
Member

asturur commented Aug 26, 2017

I m undecided if to ouput the version for each object ( since someone may be storing individual objects and not full canvases for any reason ) or output just in canvas and then modify ( a lot ) the reload process to pass down the version property.

Suggestions?

@blobinabottle
Copy link
Contributor Author

By object is a good idea. Much more flexible. I see in my workflow I work a lot by outputting the object in console. It's a detail but it could help spot bugs quicker I think :)

@asturur
Copy link
Member

asturur commented Aug 27, 2017

so i opened #4251 and added here a snippet that could convert the old designs:

http://jsfiddle.net/fmgXt/852/

i still have to solve the positioning problem, will do asap.

@asturur
Copy link
Member

asturur commented Aug 28, 2017

Could you try if this solve all the loading of all designs?

fabric.Image.fromObject = function(object, callback) {
      fabric.util.loadImage(object.src, function(img, error) {
        if (error) {
          callback && callback(null, error);
          return;
        }
        fabric.Image.prototype._initFilters.call(object, object.filters, function(filters) {
          object.filters = filters || [];
          fabric.Image.prototype._initFilters.call(object, [object.resizeFilter], function(resizeFilters) {
            object.resizeFilter = resizeFilters[0];
            if (typeof object.version === 'undefined') {
              var elWidth = img.naturalWidth || img.width;
              var elHeight = img.naturalHeight || img.height;
              var scaleX = (object.scaleX || 1) * object.width / elWidth;
              var scaleY = (object.scaleY || 1) * object.height / elHeight;
              object.width = elWidth;
              object.height = elHeight;
              object.scaleX = scaleX;
              object.scaleY = scaleY;
            }
            var image = new fabric.Image(img, object);
            callback(image);
          });
        });
      }, null, object.crossOrigin);
};

http://jsfiddle.net/fmgXt/855/

@asturur
Copy link
Member

asturur commented Aug 29, 2017

Did someone tried the above code?

@blobinabottle
Copy link
Contributor Author

On my end this is working! Thank you! Will you add this to Breaking change page? Do you think it could be useful to add these functions that help migrate from 1.7 to 2.0 into fabric.utils?

@asturur
Copy link
Member

asturur commented Aug 30, 2017

i asked on purpose, i added it but with no internet from home is hard to publish things now.

@asturur
Copy link
Member

asturur commented Aug 31, 2017

@blobinabottle do you made extensive use of filters? i think some parameters changed in filters.
Like brightness and some other moved from a -100 to 100 approach to -1 to 1

@blobinabottle
Copy link
Contributor Author

No we just used Tint until now. But I'll check if it's working with Brightness and some others.

@blobinabottle
Copy link
Contributor Author

Doesn't seems to work:
Beta 2: http://jsfiddle.net/fmgXt/859/
screen shot 2017-09-01 at 01 07 58
VS 1.7 (how it should look): http://jsfiddle.net/fmgXt/860/
screen shot 2017-09-01 at 01 07 33

@blobinabottle
Copy link
Contributor Author

As you said it's because of the 0-1 0-100 (or more, here contrast is 136 in Fabric 1.7)

@asturur
Copy link
Member

asturur commented Sep 1, 2017

so i ll prepare a file that keep all the translations of values.
So that people can include it AFTER fabricjs and having the fromObject functions changed with the one that take care of fixing the values.

Webgl has an higher precision in filtering, so it makes no sense to give it -100 + 100, -1 to +1 with any step is fine.

When getting back on the canvas everything is translated to 0 - 255 so most of this precision get lost.

@milesce
Copy link

milesce commented Sep 22, 2017

I wonder where things stand on this. I'm now testing with 2.0.0b7 and find that I cannot load canvas from JSON if its an older JSON (I have a large number of projects, etc. which were composed under earlier versions).

Currently I load using: faceCanvas.loadFromJSON(jsonString);

When I call this it errors:

TypeError: undefined is not an object (evaluating 'klass.fromObject') - fabric.js line 902

@asturur
Copy link
Member

asturur commented Sep 22, 2017

Do you have custom classes?
Some breakage may happen, where possible i m giving transfer function, the filter values one still pending.

@milesce
Copy link

milesce commented Sep 22, 2017

No custom classes. Would it help to give an example JSON? This is one that was created in and loads fine in 1.7.17 and 1.7.19 but fails to load on 2.0.0b7. If there's something I can do to help it translate it would be fantastic:

{"objects":[{"type":"path-group","originX":"left","originY":"top","left":-48.28,"top":15.81,"width":818.43,"height":320.4,"fill":"","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":0.7,"scaleY":0.7,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"paths":[{"type":"rect","originX":"left","originY":"top","left":336.57,"top":-160.92,"width":145.6,"height":817.04,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":[6.123233995736766e-17,1,-1,6.123233995736766e-17,656.97,-161.78],"skewX":0,"skewY":0,"rx":0,"ry":0},{"type":"circle","originX":"left","originY":"top","left":689.63,"top":70.66,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":689.63,"top":136.39,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":623.9,"top":70.66,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":623.9,"top":136.39,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":558.17,"top":70.66,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":558.17,"top":136.39,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":492.44,"top":70.66,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":492.44,"top":136.39,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":426.71,"top":70.66,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":426.71,"top":136.39,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":360.98,"top":70.66,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":360.98,"top":136.39,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":295.25,"top":70.66,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":295.25,"top":136.39,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":229.52,"top":70.66,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":229.52,"top":136.39,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":163.79,"top":70.66,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":163.79,"top":136.39,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":98.06,"top":70.66,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":98.06,"top":136.39,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":689.63,"top":0,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":623.9,"top":0,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":558.17,"top":0,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":492.44,"top":0,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":426.71,"top":0,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":360.98,"top":0,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":295.25,"top":0,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":229.52,"top":0,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":163.79,"top":0,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":98.06,"top":0,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"rect","originX":"left","originY":"top","left":405.85,"top":-221.89,"width":6.73,"height":818.43,"fill":{"type":"linear","coords":{"x1":-3045.8,"y1":-1184.91,"x2":-2227.37,"y2":-1184.91},"colorStops":[{"offset":1,"color":"rgb(253,214,96)","opacity":1},{"offset":0.88,"color":"rgb(255,251,204)","opacity":1},{"offset":0.75,"color":"rgb(238,214,136)","opacity":1},{"offset":0.6,"color":"rgb(195,146,46)","opacity":1},{"offset":0.57,"color":"rgb(204,162,70)","opacity":1},{"offset":0.5,"color":"rgb(231,210,142)","opacity":1},{"offset":0.44,"color":"rgb(248,240,187)","opacity":1},{"offset":0.42,"color":"rgb(255,251,204)","opacity":1},{"offset":0.27,"color":"rgb(251,201,38)","opacity":1},{"offset":0.19,"color":"rgb(245,219,132)","opacity":1},{"offset":0.14,"color":"rgb(243,227,173)","opacity":1},{"offset":0.11,"color":"rgb(235,214,154)","opacity":1},{"offset":0,"color":"rgb(210,172,88)","opacity":1}],"offsetX":-405.85,"offsetY":221.89,"gradientTransform":[6.123233995736766e-17,-1,1,6.123233995736766e-17,1594.13,-2449.26]},"stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":[6.123233995736766e-17,1,-1,6.123233995736766e-17,596.54,-221.89],"skewX":0,"skewY":0,"rx":0,"ry":0},{"type":"circle","originX":"left","originY":"top","left":34.45,"top":70.66,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":34.45,"top":136.39,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":34.45,"top":0,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":756.84,"top":70.66,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":756.84,"top":136.39,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586},{"type":"circle","originX":"left","originY":"top","left":756.84,"top":0,"width":27.7,"height":27.7,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"radius":13.85,"startAngle":0,"endAngle":6.283185307179586}]}],"background":"transparent"}

@asturur
Copy link
Member

asturur commented Sep 22, 2017

Any pathgroup? pathgroup needs a special import that is in the docs on fabricjs.com

@milesce
Copy link

milesce commented Sep 25, 2017

That makes sense. At least some of the objects I'm trying to reimport contained one or more SVGs which had been added to the canvas, then serialized. I'm having trouble finding there the special import is in the documents. loadFromJson worked fine prior to v2.0.0, but I'm hoping to make the jump to 2.0.0 asap because the handling of newly imported SVGs is fantastic. Can you point me in the right direction?

@asturur
Copy link
Member

asturur commented Sep 25, 2017

http://fabricjs.com/changelog

if you click the second link removed PathGroup class completely there is a code snippet that should work.

@milesce
Copy link

milesce commented Sep 25, 2017

Sweet, that did. Thank you so much for the help!

@ozooner
Copy link
Contributor

ozooner commented Oct 27, 2017

I think there are two distinct issues discussed here, I will be referencing the original issue.

So your issue is following: the image you are adding on canvas is larger than the fabric.Image dimensions, thus image is cropped. I had the same issue, my source image was 100x100, but when I created the fabric.Image as 200x200, the image would not be scaled up. I traced it back to this line, which I fixed in my branch ( @asturur is more than welcome to include it in the master, I think it should be in master)
playsignage@4e32f95#diff-c56c6cb2e511cdfed05fb41725ac66f7R470

Here is the same fiddle with fabric 2 build of my fork:
https://jsfiddle.net/fmgXt/1057/

@asturur
Copy link
Member

asturur commented Oct 31, 2017

i lost this comment.
So there is not a bug, there is just a breaking change.
Width and Height were stretching the image before and now are not doing it anymore.

they can actually reduce the image viewable are but will not stretch the image if the viewable area is bigger than the image.

I should write an example like for pathGroups on how to load old design in the new code.

@asturur
Copy link
Member

asturur commented Dec 11, 2017

Added conversion pattern for filters

@playground
Copy link

Hi, I'm having the same issue going from v1.7.3 to v.2.4.6, canvas.loadFromJSON, images are not showing at all. Is there a migration path or documentation to help resolve this issue?

@asturur
Copy link
Member

asturur commented Dec 31, 2018

http://fabricjs.com/changes-introduction follow those links. It depends what you had on the canvas.

@playground
Copy link

playground commented Dec 31, 2018

@asturur I follow the changes to remove alignX, alignY, meetOrSlice, but the images between text still aren't showing except for the logo which is still not scaling properly.

image

Here is the example json.

{
  "objects": [
   {
      "type": "text",
      "originX": "left",
      "originY": "top",
      "left": 85,
      "top": 33,
      "width": 277.43,
      "height": 31.64,
      "fill": "white",
      "stroke": null,
      "strokeWidth": 1,
      "strokeDashArray": null,
      "strokeLineCap": "butt",
      "strokeLineJoin": "miter",
      "strokeMiterLimit": 10,
      "scaleX": 1,
      "scaleY": 1,
      "angle": 0,
      "flipX": false,
      "flipY": false,
      "opacity": 1,
      "shadow": null,
      "visible": true,
      "clipTo": null,
      "backgroundColor": "",
      "fillRule": "nonzero",
      "globalCompositeOperation": "source-over",
      "transformMatrix": null,
      "skewX": 0,
      "skewY": 0,
      "text": "EXAMPLE IMAGE",
      "fontSize": 28,
      "fontWeight": "bold",
      "fontFamily": "helvetica",
      "fontStyle": "",
      "lineHeight": 1.16,
      "textDecoration": "",
      "textAlign": "left",
      "textBackgroundColor": "",
      "charSpacing": 0,
      "namespace": "title"
    },
    {
      "type": "text",
      "originX": "left",
      "originY": "top",
      "left": 325,
      "top": 306,
      "width": 40.47,
      "height": 31.64,
      "fill": "white",
      "stroke": null,
      "strokeWidth": 1,
      "strokeDashArray": null,
      "strokeLineCap": "butt",
      "strokeLineJoin": "miter",
      "strokeMiterLimit": 10,
      "scaleX": 1,
      "scaleY": 1,
      "angle": 0,
      "flipX": false,
      "flipY": false,
      "opacity": 1,
      "shadow": null,
      "visible": true,
      "clipTo": null,
      "backgroundColor": "",
      "fillRule": "nonzero",
      "globalCompositeOperation": "source-over",
      "transformMatrix": null,
      "skewX": 0,
      "skewY": 0,
      "text": "0%",
      "fontSize": 28,
      "fontWeight": "normal",
      "fontFamily": "helvetica",
      "fontStyle": "",
      "lineHeight": 1.16,
      "textDecoration": "",
      "textAlign": "left",
      "textBackgroundColor": "",
      "charSpacing": 0,
      "namespace": "text_5"
    },
    {
      "type": "image",
      "originX": "left",
      "originY": "top",
      "left": 28,
      "top": 22,
      "width": 50,
      "height": 50,
      "fill": "rgb(0,0,0)",
      "stroke": null,
      "strokeWidth": 0,
      "strokeDashArray": null,
      "strokeLineCap": "butt",
      "strokeLineJoin": "miter",
      "strokeMiterLimit": 10,
      "scaleX": 1,
      "scaleY": 1,
      "angle": 0,
      "flipX": false,
      "flipY": false,
      "opacity": 1,
      "shadow": null,
      "visible": true,
      "clipTo": null,
      "backgroundColor": "",
      "fillRule": "nonzero",
      "globalCompositeOperation": "source-over",
      "transformMatrix": null,
      "skewX": 0,
      "skewY": 0,
      "src": "https://s3.amazonaws.com/web-dig/images/fbmbot-logo.png",
      "filters": [],
      "resizeFilters": [],
      "crossOrigin": ""
      "namespace": "logo"
    },
    {
      "type": "image",
      "originX": "left",
      "originY": "top",
      "left": 166,
      "top": 137,
      "width": 45,
      "height": 45,
      "fill": "rgb(0,0,0)",
      "stroke": null,
      "strokeWidth": 0,
      "strokeDashArray": null,
      "strokeLineCap": "butt",
      "strokeLineJoin": "miter",
      "strokeMiterLimit": 10,
      "scaleX": 1,
      "scaleY": 1,
      "angle": 0,
      "flipX": false,
      "flipY": false,
      "opacity": 1,
      "shadow": null,
      "visible": true,
      "clipTo": null,
      "backgroundColor": "",
      "fillRule": "nonzero",
      "globalCompositeOperation": "source-over",
      "transformMatrix": null,
      "skewX": 0,
      "skewY": 0,
      "src": "https://s3.amazonaws.com/web-dig/wxicons/sunny.png",
      "filters": [],
      "resizeFilters": [],
      "crossOrigin": "",
      "namespace": "icon_2"
    },
  ],
  "background": "",
  "backgroundImage": {
    "type": "image",
    "originX": "left",
    "originY": "top",
    "left": 0,
    "top": 0,
    "width": 400,
    "height": 418.65,
    "fill": "rgb(0,0,0)",
    "stroke": null,
    "strokeWidth": 0,
    "strokeDashArray": null,
    "strokeLineCap": "butt",
    "strokeLineJoin": "miter",
    "strokeMiterLimit": 10,
    "scaleX": 1,
    "scaleY": 1,
    "angle": 0,
    "flipX": false,
    "flipY": false,
    "opacity": 1,
    "shadow": null,
    "visible": true,
    "clipTo": null,
    "backgroundColor": "",
    "fillRule": "nonzero",
    "globalCompositeOperation": "source-over",
    "transformMatrix": null,
    "skewX": 0,
    "skewY": 0,
    "src": "https://s3.amazonaws.com/web-dig/images/hourly.png",
    "filters": [],
    "resizeFilters": [],
    "crossOrigin": "",
    "alignX": "none",
    "alignY": "none",
    "meetOrSlice": "meet"
  }
}

@playground
Copy link

playground commented Jan 7, 2019

Hi @asturur any idea why the images aren't showing up?

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

No branches or pull requests

5 participants