Issue identified in #2067063: Wysiwyg integration is broken. See comments #68, #101, #132, and #134.
In a nutshell: image_style_transform_dimensions() will set the height and width attributes according to the image style settings, effectively overwriting any height and width attribute modifications made via the wysiwyg. I have been unable to identify any hooks or theme overrides where we might be able to cleanly re-overwrite these attributes.
The proposed solution is to ensure that height and width attribute overrides are always reflected in a style attribute, which will take precedent when rendering the image, thus ensuring that the image is rendered with the height and width as set by the user.
Comments
Comment #1
John Pitcairn CreditAttribution: John Pitcairn commentedOther implementations will want to override the dimensions in php or css, regardless of what the person editing the content in wysiwyg thinks looks OK in their wysiwyg edit form at whatever width they happen to be using that day.
If there are height and width rules added by js in an inline style attribute after the page loads, and something else expects to override those, the only way to do so is by adding an !important declaration in a stylesheet, or running more js. Everything has to escalate.
Maybe the overriding implementation wants to calculate a new width/height based on the requested width compared to something else, like the node view mode, or whatever. Maybe it needs to be pixels, or a percentage, or ems.
A js-only approach seems just as hacky as a server-side preg_replace of attributes to me. If we want an alter() hook or theme function to allow this, where might that live? It's almost certainly a better approach than post-processing in js, IMO.
Comment #2
ParisLiakos CreditAttribution: ParisLiakos commentedI was looking exactly at this this afternoon..and i couldnt think of an elegant way to override image_style_transform_dimensions()..maybe thats the only way, setting the style attribute in either php or js..maybe js is the right place to do it
i just dont understand why we do this instead of just
if (element.attr(a))
wouldnt the end result be the same and less confusing?
Comment #3
ParisLiakos CreditAttribution: ParisLiakos commentedre #1 : if you consider that this is the behavior of ckeditor when resizing images, this approach cant be that bad.
i dont like it too, but well i cant think another way
Comment #4
John Pitcairn CreditAttribution: John Pitcairn commentedI don't think ckeditor's behavior is any good either. The user-requested width and height are static attributes and are accessible on the server side, we have valid (in xhtml or html5) width and height attributes, and client-side js is not an appropriate place to be outputting those (and is difficult to override).
Personally I think it would be better for media module to override the width and height attribute in php via preg_replace(), if no better solution exists, and push for an appropriate override in image module. That way, the way is left clear for other modules to at least add a simple stylesheet without !important rules.
I will take a closer look at this too.
Comment #5
John Pitcairn CreditAttribution: John Pitcairn commentedI see. So without the patch, if the user does not override the default width and height, an inline style with default width and height is applied anyway, even though the width and height attributes are correct. This patch overrides that default inline style. I'm fine with that, my complaint is that there is an inline style in the first place.
I can still manipulate or remove the inline style and attributes prior to rendering. No further objections from me here.
Comment #6
David_Rothstein CreditAttribution: David_Rothstein commentedHere's a version that works with #2126755: Improve Media's WYSIWYG Macro handling applied. I gave it the "do-not-test" suffix since the patch won't apply otherwise.
Comment #7
David_Rothstein CreditAttribution: David_Rothstein commentedFixing component.
Comment #8
asrobHi,
it works well on my local development environment. I attached two images and they have different sizes in ckeditor and after submitted node they're looking good.
Comment #9
joseph.olstadRerolled, patch still applied, but with offset, just rerolling it and run it against the testbot.
Comment #10
joseph.olstadprobably needs a re-review, due to the new functionality in the latest versions of media
Comment #11
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commented