ckeditor5 icon indicating copy to clipboard operation
ckeditor5 copied to clipboard

Implement the image resize handler

Open oleq opened this issue 8 years ago β€’ 46 comments

The functionality of the enhanced image plugin in v4 is missing in v5.

image

A follow-up of https://github.com/ckeditor/ckeditor5/issues/1330.


If you'd like to see this feature implemented, add πŸ‘ to this post.

oleq avatar Oct 30 '18 16:10 oleq

i'm very excepted to see this feature can be implemented ! thank you again ! Ckeditor is the best editor !

100cm avatar Oct 31 '18 01:10 100cm

Thank you guys for the awesome editor. Any news on this item?

programad avatar Dec 06 '18 17:12 programad

@programad It's in our backlog ATM, which means it's among our top priorities. But there are so many of features like this one I cannot tell you the exact ETA.

oleq avatar Dec 07 '18 15:12 oleq

The feature has been requested in https://github.com/ckeditor/ckeditor5/issues/1401.

oleq avatar Dec 20 '18 10:12 oleq

Thanks for the awesome work on CKEditor 5. This feature is essential to any CMS that supports image uploads.

bizsimon avatar Feb 14 '19 18:02 bizsimon

I am planning on integrating it in our company and getting the license. But, the image resize is a very important feature for us to use this editor. Any ideas, if this feature has a chance to make to production.

mechanicals avatar Apr 24 '19 10:04 mechanicals

As you might see we started working on this in this iteration. Though the date is not written in the stone just yet, we currently plan to release this iteration somewhere between 4-6th of June.

That being said, the feature will land in the code repository earlier than that. So if you can't wait to play with image resizing, be sure to subscribe this issue so that you're notified when the feature is available for the preview.

mlewand avatar Apr 25 '19 06:04 mlewand

I did some research on that matter. Below are the findings.

Image Resize

First off, not only image requires resizing, there are few candidates that might use it:

  • image
  • media embed
  • table

Discussion

Handlers (must-have)

  • multiple resize handlers
    • Google docs Google docs resizing grid - 8 points
    • Firefox/IE native contenteditable implementation
    • MS Word Multiple resize handlers for MS Word
    • TinyMCE 4 handlers in TinyMCE
    • Froala Froala 4 handlers
  • single handler
    • CKE4: CKEditor4 simplified resizing handler
    • Prose mirror 3rd party contrib: Prose mirror 3rd party contribution
    • Redactor Redactor image resizer

Based on the trends we should start with multiple resize handlers. There are a few pros for that:

  • people are more familiar with it,
  • we don't have to worry about bidi,
  • aspect ratio issue (see "Aspect ratio" section) is solved

The main issue is that it clutters the UI once the resized entity gets hovered/focused.

Handlers position

Often times we're using captioned image. In that case it sounds only fair to bound handlers to the wrapper.

Aspect ratio

Should aspect ratio be locked? Should interface allow to lock unlock aspect ratio? Or maybe should it only be doable with keyboard modifier, e.g. holding a shift/alt or not.

Having multiple resize handlers, we can skip the feature and force corner handlers to keep the aspect ratio, while others will resize only along a single axis.

Limiters

One might desire an option to constrain min and max size of resized object.

Accessibility

Any feature of the editor should be accessible, this includes resizing too.

As an example for shapes (this does not include image) MS Word support shift+arrow. It supports alt+arrow for rotating images.

Accessibly doesn't necessairly needs be implemented as handling resizing using arrow. If we'd have some sort of accessible dialog that would allow for setting the size, that would be fine too.

Widget Features

Since this particular feature will be reused over other widgets it has to be implemented with a reusable API. We can think of it as a widget feature that should not be limited to images only.

There are several candidates like that:

  • resize
  • drag and drop
  • upload
  • overlay

So it would make sense to create a common API called widget features, that would serve as a framework for such drop-in self-contained feature implementations.

API

An example API might look something like that:

import { toWidget } from '@ckeditor/ckeditor5-widget/src/utils';
import { ResizeFeature } from '@ckeditor/ckeditor5-widget-feature-resize/src/resize';

// Simplest, hardcoded usage:

// (…)
return toWidget( viewElement, writer, {
		label: labelCreator
		features: [
			ResizeFeature(),
			DragAndDropFeature()
		]
	} );

// More realistic, configurable usage:
// (…)
let features = [];

if ( config.image.resize !== false ) {
	features.push( ResizeFeature( config.image.resize ) );
}

if ( config.image.dragAndDrop ) {
	features.push( DragAndDropFeature( config.image.dragAndDrop ) );
}

return toWidget( viewElement, writer, {
		label: labelCreator,
		features: features
	} );

Note this is just a concept, I haven't yet verified it with any PoC.

Summary

IMHO our implementation should feature multiple resizers. It gives more functionality, we also don't have to worry about aspect ratio and bidirectional lang handling at a cost of slightly cluttered UI.

As for API I need to prepare PoC first to figure out if it plays the way I expect it to do. There's one thing that I'm worried about, where I'd need static listeners that should be initialized despite a widget was created or not (e.g. upload widget feature, that would listens for drops over the editable containing a certain mime type).

mlewand avatar Apr 26 '19 14:04 mlewand

@mlewand Hey. when will be this on live on master branch? I was not able to find this module @ckeditor/ckeditor5-widget-feature-resize/src/resize

can you let me know how i can install/use this module in ckeditor-5

saravana34 avatar May 08 '19 07:05 saravana34

@saravana34 we're still in the design phase. We aim to ship it within current iteration. Subscribe the issue and you'll get notified once the pre-release is ready πŸ™‚

mlewand avatar May 08 '19 08:05 mlewand

I hope this can be done soon , it is a necessary feature

kamalkemo avatar May 13 '19 01:05 kamalkemo

This is feature is a really good one, so please make add it in thank you, guys.

Nothing-Works avatar May 22 '19 09:05 Nothing-Works

this is feature is good, i need feature !!!

sunkid1995 avatar May 28 '19 07:05 sunkid1995

Almost a year in the past,any process on this?

100cm avatar May 28 '19 07:05 100cm

@mlewand looking forward for the fix.. please keep us updated

premsanth-rajamani avatar Jun 11 '19 10:06 premsanth-rajamani

Any update or walk through?

swebsas avatar Jun 28 '19 14:06 swebsas

@swebsas Iteration 26 roadmap includes it and its due on August 19th. it's coming, finally :)

bizsimon avatar Jul 25 '19 01:07 bizsimon

πŸŽ‰ Preview available πŸŽ‰

Hey all! We've been silent for last couple of weeks as we've been working hard to prepare a preview of our image resize feature and I'm pleased to share it with you.

You can find it on https://ckeditor5.github.io/misc/image-resize/ - please give it a try!

Introduction

The image resize handlers will be shown once you focus the image (click it or navigate there using the keyboard).

There are couple of details, like inconsistent cursor or resizers not disappearing when editor is blurred - which we're aware and will be ironed out during next couple of days.

Feedback needed

There are couple of questions that we'd like to ask community:

  • The image size is saved as inline width style applied to img element in pixels. We're wondering whether there are use cases when you'd like to use percents rather than pixels? If so please, let us know the use cases.
  • By default CKEditor's 5 side images have max-width limited to 50%. It doesn't feel right to be limited to that when using the resize feature, so we decided to add a class ck_resized to the figure once image is resized - in which case it doesn't have this limitation. It also gives an easy option to customize it in case developer decides that such images should be in fact limited. We don't see any downsides here, but feel free to share your opinion.

Naturally if you'd like to share any thought beyond that, feel free to do so!

Timing

We also decided to push back the release by one week so we have more time to discuss it.

mlewand avatar Aug 07 '19 12:08 mlewand

Great job, @mlewand! Resizing works great πŸ‘

The image size is saved as inline width style applied to img element in pixels. We're wondering whether there are use cases when you'd like to use percents rather than pixels? If so please, let us know the use cases.

All the RTEs use pixels, but I think this is wrong. This makes the images completely unresponsive. How do you know how wide the content that you're displaying will be? The column with the text may have 900px on desktop, but 500px on mobile.

Therefore, I think we should use percentage values. This will ensure that images scale well with the content. E.g. we use percentage values in the default image styles (side image has max-width 50%).

However:

  • Should the feature be using percentage values by default?
  • Should we support both modes? Or can we support only percentage values?
  • How will percentage values work in tables?

By default CKEditor's 5 side images have max-width limited to 50%. It doesn't feel right to be limited to that when using the resize feature, so we decided to add a class ck_resized to the figure once image is resized - in which case it doesn't have this limitation. It also gives an easy option to customize it in case developer decides that such images should be in fact limited. We don't see any downsides here, but feel free to share your opinion.

I generally like this idea. It makes the image styles and image resizing features cooperate well. You first make the image "aside" (or "left/right/center aligned", depending on your settings) and the image momentarily changes its width to the hardcoded 50%. But thanks to the image resize feature, you can override that value. Once you start resizing, the image's style should be overriden and for that we need the new class.

By using the class we give the developers full control over how they are going to handle that. E.g. one may decide to set min/max-widths for resized images too.

The only minor detail is that this class should rather look like ck-image__resized, AFAIK.

Reinmar avatar Aug 07 '19 13:08 Reinmar

I am missing a way to bring back the image to the original size. I could see that as a button in image toolbar or even like double-clicking on a resize handler.

scofalik avatar Aug 07 '19 14:08 scofalik