processwire-issues icon indicating copy to clipboard operation
processwire-issues copied to clipboard

ProcessPageEditImageSelect shouldn't resize an image based on the current user's browser size

Open jlahijani opened this issue 1 year ago • 1 comments

This has been a quirk (not necessarily a bug, but it feels like one) with what ProcessWire does to an image that you uploaded and are about to insert into a rich text field (CKE or TinyMCE).

When you select an uploaded image to insert into CKEditor or the new TinyMCE, the width it inserts it at (assuming you haven't touched any other settings), defaults to the width of the person's browser (minus the general padding and such of the interface) instead of the original image width which feels more correct. Furthermore, it doesn't set a height in the inserted image html attributes.

Separately, when you resize an image within TinyMCE itself, it will actually insert the height attribute for the newly resized image which is good. However it should do that when the image is inserted originally as mentioned above.

jlahijani avatar Feb 06 '24 23:02 jlahijani

I fixed the part that the image gets auto resized based on user's browser screen with a hook on init.php so I can get the original size.

$wire->addHookAfter('ProcessPageEditImageSelect::executeEdit', function(HookEvent $event) {

    $event->return .= "
    <script>
        $('#selected_image_container').attr('style','width: '+$('#selected_image').data('origwidth')+'px; height: '+$('#selected_image').data('origheight')+'px');
        $('#selected_image').attr('data-fit','');
    </script>";
    
});

PWaddict avatar Feb 14 '25 09:02 PWaddict