Roberto Nicchi Posted June 17, 2022 Share Posted June 17, 2022 Would be useful if in a future version of UNIGUI you add a function in TuniHTMLMemo that allows to: 1) Insert an embedded image into the HTML (copy and paste would be great) 2) Resize the inserted image using mouse. thanks Roberto Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 17, 2022 Share Posted June 17, 2022 Hello, Also this post may help you: http://forums.unigui.com/index.php?/topic/5856-ckeditorelfinder-in-unigui-possible/ Quote Link to comment Share on other sites More sharing options...
Roberto Nicchi Posted June 17, 2022 Author Share Posted June 17, 2022 5 hours ago, Sherzod said: Hello, Also this post may help you: http://forums.unigui.com/index.php?/topic/5856-ckeditorelfinder-in-unigui-possible/ Hello, i have checked the post but i'm afraid it's not what i need. The first and most important problem is that the image is not embedded into the html. The image is uploaded into a directory of the HD. I need the image is embedded into the html because the html will be used as a body for an email. Email that is sent using Indy. And, secondary, the image can't be resized after it's been displayed into the html memo thanks Quote Link to comment Share on other sites More sharing options...
Oliver Morsch Posted June 18, 2022 Share Posted June 18, 2022 1. Take the (uploaded) image and encode it into base64. 2. Create a data URI by replacing "[Base64EncodedString]" with the the base64 encoded image in the following html code: <img src="data:image/jpeg;base64,[Base64EncodedString]" /> 3. Insert this html code into htmlmemo. Quote Link to comment Share on other sites More sharing options...
Oliver Morsch Posted June 18, 2022 Share Posted June 18, 2022 example: <img src="data:image/png;base64,iVBORw0KGgoAAA ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4 //8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU 5ErkJggg==" alt="Red dot" /> Quote Link to comment Share on other sites More sharing options...
Roberto Nicchi Posted June 18, 2022 Author Share Posted June 18, 2022 6 hours ago, Oliver Morsch said: example: <img src="data:image/png;base64,iVBORw0KGgoAAA ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4 //8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU 5ErkJggg==" alt="Red dot" /> Hello, i have almost done it. I have an exception "Invalid or unexpected token" in the line UniSession.AddJS( Look at my code below. If i replace the encoding code with a constant encoded text (the one from your example) i see that the image (red dot) is correctly inserted into the htmlmemo So i guess there's a mistake in how i'm encoding the image. My code is wrong ? procedure TMainForm.UniFileUpload1Completed(Sender: TObject; AStream: TFileStream); var htmltext:string; encodedimage: String; sstream:TStringStream; begin sstream:=TStringStream.Create; try encodestream(astream,sstream); encodedimage:=sstream.DataString; finally sstream.free; end; // encodedimage:='iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='; htmltext:='<img src="data:image/jpeg;base64,'+encodedimage+'" />'; UniSession.AddJS(UniHTMLMemo1.JSName + '.execCmd(''InsertHTML'', '''+htmltext+''')'); end; Quote Link to comment Share on other sites More sharing options...
Oliver Morsch Posted June 18, 2022 Share Posted June 18, 2022 I think your base64 encoding ist wrong. Try tnetencoding.base64.encode. Quote Link to comment Share on other sites More sharing options...
Roberto Nicchi Posted June 19, 2022 Author Share Posted June 19, 2022 12 hours ago, Oliver Morsch said: I think your base64 encoding ist wrong. Try tnetencoding.base64.encode. I changed the encoding code in sstream:=TStringStream.Create; try tnetencoding.base64.encode(astream,sstream); encodedimage:=sstream.DataString; finally sstream.free; end; but didn't help. Seems i have found the solution anyway: have to remove line breaks in the encoded text. encodedimage:=StringReplace(StringReplace(encodedimage, #10, ' ', [rfReplaceAll]), #13, ' ', [rfReplaceAll]); I only miss the possibility to resize the image but i can live without it ... for the moment. To set in HTML the image width helps. I see that if i set the width, the height is calculated automatically and the image is not stretched. htmltext:='<img width="300" src="data:image/jpeg;base64,'+encodedimage+'" />'; thanks for your help Roberto Quote Link to comment Share on other sites More sharing options...
Oliver Morsch Posted June 19, 2022 Share Posted June 19, 2022 With tinyMCE (See Forum) you can resize images and much more... Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 19, 2022 Share Posted June 19, 2022 2 hours ago, Roberto Nicchi said: I only miss the possibility to resize the image but i can live without it ... for the moment. Hello, I sent you a PM. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.