RichEditorView icon indicating copy to clipboard operation
RichEditorView copied to clipboard

Need a way to edit/set/reduce image size

Open xumx opened this issue 9 years ago • 8 comments

photos from insertImage can be huge. Is there anyway to change/set the display size to 50% width etc.

Something like what Summernote is doing.

style="width: 50%"

xumx avatar Feb 20 '16 12:02 xumx

Yeah, I agree, something like this should be in there. I'll see what I can whip up.

cjwirth avatar Feb 22 '16 02:02 cjwirth

Sorry that I am super late on this, but you can always inject a viewport inside the meta tag of the html before setting it on the editor. That's how I solved this exact problem without losing quality of the image.

markchous avatar Jun 21 '17 13:06 markchous

Hello guys, can anyone explain the solution in detail?

swapnalishinde avatar Nov 15 '17 12:11 swapnalishinde

Got the solution but we need to modify some of the files: simulator screen shot 16-nov-2017 6 06 15 pm

swapnalishinde avatar Nov 16 '17 12:11 swapnalishinde

Any update on this?

tnylee avatar Mar 06 '18 15:03 tnylee

@markchous Can you please explain more on your solution? Thanks!

tnylee avatar Mar 06 '18 15:03 tnylee

can you please share modified code

sultansultanm97 avatar Feb 25 '19 17:02 sultansultanm97

You can do something like:

func insertImage(editor: RichEditorView, src: String, width: Int? = nil, height: Int? = nil, alt: String = "") {
    let finalWidth = width == nil ? "auto" : "\(width!)px"
    let finalHeight = height == nil ? "auto" : "\(height!)px"
    editor.html += "<img src=\"\(src)\" alt=\"\(alt)\" style=\"width: \(finalWidth); height: \(finalHeight); max-width: 100%;\" /><br />"
    editor.runJS("RE.focus()") // Move cursor to a newly added line
}

Note that I've used the max-width constraint to not to overflow the max width of a web view, you may add/remove it on your own (or add a max-height as well)

pandomic avatar May 02 '20 21:05 pandomic