When the image download finishes, CKEditor replaces the boot widget (which contains the image with Base64 data in the source) with the final HTML. The downloaded image is the same size as the loaded image to prevent blinking during this replacement. Here are the lines that make this replacement.
If blinking while loading an image is not a problem for you, you can simply overwrite this method:
editor.on( 'instanceReady', function() { editor.widgets.registered.uploadimage.onUploaded = function ( upload ) { this.replaceWith( '<img src="' + upload.url + '">' ); } } );
Now, where can we get image sizes from?
One option is to upload an image ( upload.url ) and read its size in a browser. However, this is an asynchronous operation, so it can affect the cancellation manager, and I would not recommend it.
Therefore, if you know new measurements that you can send then in the server response. If you put them in your JSON response as follows:
{ "uploaded": 1, "fileName": "foo.jpg", "url": "/files/foo.jpg", "width:" 300, "height:" 200 }
You need to process them in the answer (we will most likely simplify this bit in the near future):
editor.on( 'fileUploadResponse', function( evt ) { var fileLoader = evt.data.fileLoader, xhr = fileLoader.xhr, data = evt.data; try { var response = JSON.parse( xhr.responseText );
To learn more, editor#fileUploadResponse , and Download files with drop-down or file attachments .
Then you can use them in download widgets:
editor.on( 'instanceReady', function() { editor.widgets.registered.uploadimage.onUploaded = function( upload ) { this.replaceWith( '<img src="' + upload.url + '" ' + 'width="' + upload.width + '" ' + 'height="' + upload.height + '">' ); } } );
PS. We considered the possibility of including such a function in the kernel, but since the release was huge, we had to at some point limit it so that it finally came to life. There is a high probability that such a function will be included in the main core in the near future, and only configuration is required.