Summernote: Responsive Image width / size using onimageupload?

Created on 31 May 2017  路  1Comment  路  Source: summernote/summernote

I know we already have the issues here and here . But both give users the task to change image to percentage width.

If they do not act on this, the corresponding image will be displayed with fixed width as shown below.
<img src="data:image/jpeg;base64,/9j/4Qk... ...sv6+zE//Z" data-filename="image.jpg" **style="width: 768px;">**

I want all images to be styled like below:
<img src="data:image/jpeg;base64,/9j/4Qk... ...sv6+zE//Z" data-filename="image.jpg" **style="width: 100%;">**

Is it possible to configure Style permanently without user intervention? Maybe using imageupload?

Most helpful comment

I have got a solution for this problem inspired by answer of @easylogic on issue#1069.

I have used the following code:

       onImageUpload : function(files) {
      if (!files.length) return;
      var file = files[0];
      // create FileReader
      var reader  = new FileReader();
      reader.onloadend = function () {
          // when loaded file, img's src set datauri
          console.log("img",$("<img>"));
          var img = $("<img>").attr({src: reader.result, width: "100%"}); // << Add here img attributes !
          console.log("var img", img);
          $(TariffHTMLId).summernote("insertNode", img[0]);
      }

      if (file) {
        // convert fileObject to datauri
        reader.readAsDataURL(file);
      }
  }

>All comments

I have got a solution for this problem inspired by answer of @easylogic on issue#1069.

I have used the following code:

       onImageUpload : function(files) {
      if (!files.length) return;
      var file = files[0];
      // create FileReader
      var reader  = new FileReader();
      reader.onloadend = function () {
          // when loaded file, img's src set datauri
          console.log("img",$("<img>"));
          var img = $("<img>").attr({src: reader.result, width: "100%"}); // << Add here img attributes !
          console.log("var img", img);
          $(TariffHTMLId).summernote("insertNode", img[0]);
      }

      if (file) {
        // convert fileObject to datauri
        reader.readAsDataURL(file);
      }
  }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

sgthangtran picture sgthangtran  路  4Comments

johandanforth picture johandanforth  路  3Comments

bbyrdhouse picture bbyrdhouse  路  4Comments

wstaelens picture wstaelens  路  3Comments

hanct picture hanct  路  3Comments