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

Why does an image change its size after being uploaded #2552

Closed
Reinmar opened this issue Sep 27, 2017 · 14 comments
Closed

Why does an image change its size after being uploaded #2552

Reinmar opened this issue Sep 27, 2017 · 14 comments
Labels
package:easy-image status:discussion type:bug This issue reports a buggy (incorrect) behavior.
Milestone

Comments

@Reinmar
Copy link
Member

Reinmar commented Sep 27, 2017

sep-27-2017 20-21-34

@Reinmar
Copy link
Member Author

Reinmar commented Sep 27, 2017

cc @pjasiun @oskarwrobel

@Reinmar Reinmar changed the title Why does the image change its size after being uploaded Why does an image change its size after being uploaded Sep 27, 2017
@fredck
Copy link
Contributor

fredck commented Sep 28, 2017

It's like the image has been scaled up, and this should not happen. Or maybe it's just my impression.

@Reinmar
Copy link
Member Author

Reinmar commented Sep 28, 2017

I think that this might be caused by the progress bar styles. Perhaps they use something like pos:rel, overflow:hidden which might affect the layout.

@szymonkups
Copy link
Contributor

szymonkups commented Sep 28, 2017

It looks like the browser is picking one of the images returned from the server and placed inside srcset attribute. We have sizes="100wv", so browser will choose image with width closest to browser width. So it goes like this:

  • we are reading file from disk and putting it in the view during the upload, this image has smaller width than editor, so it is not taking all the space,
  • response from the server is returned, there is a bigger image in srcset attribute, with width closer to the browser's width, so it is picked, and now it is taking all the space in editor.

@pjasiun
Copy link

pjasiun commented Sep 28, 2017

According to this article setting width attribute to the maximum (original) image width could help.

@szymonkups
Copy link
Contributor

My previous comment is wrong - server cannot return image with bigger width than it is loaded from disk.

@Reinmar
Copy link
Member Author

Reinmar commented Sep 28, 2017

To save you a couple of minutes, @pjasiun meant this:

As long as you can specify the width attribute so it reflects the true maximum size of your largest image, you won’t run into this problem of having sizes make your image wider than it naturally should go.

So, together with sizes we should always set width. Is this correct?

@pjasiun
Copy link

pjasiun commented Sep 28, 2017

Most probably, but we need to check it. I did only quick research.

Anyway, sizes seems to be oddly designed. It supposes to be a property to define which values from the srcset should be taken. sizes=100vw should only mean that the values from srcset should be taken based on the viewport width. It should do nothing with the image width. Instead, it changes image width if the biggest image is smaller then container, and apparently, it's not only we who meet this problem. This is strange. But who I am to judge W3C decisions? /cc @Comandeer

@Reinmar
Copy link
Member Author

Reinmar commented Sep 28, 2017

[OT] The whole sizes topic that we've struggled with previously and now this... It's, I think, the first time in my career that I'm too tired to be curious WTH. This is sad ;| [/OT]

@Comandeer
Copy link
Member

Comandeer commented Sep 28, 2017

But who am I to judge W3C decisions?

Actually description of this attribute in W3C's specification is very laconic and it's not even a requirement to include it alongside [srcset]:

If the srcset attribute is present, the sizes attribute may also be present.

More interesting version of it is inside WHATWG's specification:

If the srcset attribute is present and has any image candidate strings using a width descriptor, the sizes attribute must also be present, and is a sizes attribute. The sizes attribute contributes the source size to the source set (if no source element was selected).

Source size:

A source size is a <source-size-value>. When a source size has a unit relative to the viewport, it must be interpreted relative to the img element's node document's viewport. Other units must be interpreted the same as in Media Queries.

Sizes attributes:

The <source-size-value> gives the intended layout width of the image.

So I doubt it is really W3C's decision ;) In fact AFAIK it originates from RICG (Responsive Image Community Group) from their work on picture tag. And deep in RICG's archive I found an explanation why [width] attribute is more important than [sizes].

@pjasiun
Copy link

pjasiun commented Sep 28, 2017

To conclude. The server, when returning the set of values to be used in srcset should ensure that the maximum value is equals default. It should be noted in the docs. This value should be used to set width. And we should be fine, I hope.

Note: that if the default value is the biggest we will set too small width, and if default value is smaller we will set width bigger than the width of image src, what will not be fine on browsers which do not support responsive images (IE 11).

@pjasiun
Copy link

pjasiun commented Sep 28, 2017

It means that the proper JSON returned from the server is, for instance:

{
   'default': 'http://example.com/image_300.jpg',
   '300': 'http://example.com/image_300.jpg',
   '200': 'http://example.com/image_200.jpg',
   '100': 'http://example.com/image_100.jpg'
}

pjasiun referenced this issue in ckeditor/ckeditor5-image Sep 29, 2017
Feature: Replaced srcset attribute in the model by responsive attribute which is now converted to three attributes in the view: srcset, sizes and width. Closes #145. Closes ckeditor/ckeditor5-easy-image#4.

BREAKING CHANGE: The srcset attribute is now replaced by responsive attribute in the model.
@mlewand mlewand transferred this issue from ckeditor/ckeditor5-easy-image Oct 9, 2019
@mlewand mlewand added this to the iteration 12 milestone Oct 9, 2019
@mlewand mlewand added status:discussion type:bug This issue reports a buggy (incorrect) behavior. package:easy-image labels Oct 9, 2019
@dzpt
Copy link

dzpt commented Oct 2, 2020

@pjasiun how do i add more data on this json?
like data-id?

@ma2ciek
Copy link
Contributor

ma2ciek commented Mar 31, 2021

Hi @dzpt,

Your request is a dup of #5204 which will be resolved soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:easy-image status:discussion type:bug This issue reports a buggy (incorrect) behavior.
Projects
None yet
Development

No branches or pull requests

8 participants