When you insert an image into a TWebBrowser in edit mode, how do you get the filepath of the inserted image? When an image is inserted it includes the full path to the image in the html source, but in my case I need to modify the html source to only include the filename.
EDIT:
This is the html source after the image is inserted:
<IMG border=0 hspace=0 alt=delphi align=baseline
src="C:\Images\delphi.bmp">
I need to change
<IMG border=0 hspace=0 alt=delphi align=baseline
src="C:\Images\delphi.bmp">
to
<IMG border=0 hspace=0 alt=delphi align=baseline
src="HTML\delphi.bmp">
Yes I can get the path from the html but I'd like to try to copy the image file to the HTML folder then change the path to the HTML folder after the image is inserted without parsing the html. If the filepath can be obtained after the image is inserted I can add the code to copy the file to the HTML folder so that the image appears in the webbrowser with the new path...
Have you tried using the browser's DOM interfaces to read the src attribute and update it to what you want? Specifically, look at the src property of the IHTMLImgElement interface.
Related
Am using SwiftyMarkdown framework to render my .md file to have dynamic formatted data in my VC. But i am not able to load images in my document directory referenced in .md file. I can load images if they are available in Bundle.
Any other option or framework to fix this issue? I want to dynamically load images from server and save them documents directory and refer them in .md file which is also saved in same documents directory/folder. So the url of image and .md file is same.
"MyFile.md" in documents directory contains below content
Continue your walk, joining up with your original perimeter path of the item. "
In my VC viewdidload, i access the url path and load nsattributed string to my textview using SwiftyMarkdown frmaework
let url = self.getDocumentsDirectory().appendingPathComponent("MyFile.md")
if let md = SwiftyMarkdown(url: url) {
textView.attributedText = md.attributedString()
}
The formatted text is loaded but no image as its not available in my Bundle. But its saved in the same document directory as that of "MyFile.md"
Hope its clear!
I have a html page which has input field(my panel html). I need get path to image(in my file system) from input and set it to <img src = "path">(in tab html). I know that browser don't allow to get absolute path to file.
Questions:
1) How can I copy image to my resource:data directory to get images relative path and set it to my <img src>?
2) Are there another alternatives to set path in img src to any image in my file system?
Please see Nandu's solution. You cannot set src of an image to a file:// uri.
Option 1
Make your panel.html a privileged page. Add a chrome.manifest file to your addon, and load the page into the panel with your chrome://***/content/*** path and it can now load file uris.
OR register your resource page as an about: page with this - https://developer.mozilla.org/en-US/docs/Custom_about:_URLs
Option2
Create a resource:// for it then set your src to that.
You can create a resource like this:
let res = Services.io.getProtocolHandler("resource").QueryInterface(Ci.nsIResProtocolHandler);
res.setSubstitution("myAddonId/myimg", Services.io.newURI('file://blah/blah/blah.png',null,null));
Then set src to resource://myAddonId/myimg
Option 3
XHR the image set the responseType = 'blob' and then on the resulting blob do URL.createObjectURL and then set the src of the img to that.
To show a file dialog and get file path do this:
var fp = Cc['#mozilla.org/filepicker;1'].createInstance(Ci.nsIFilePicker);
fp.init(Services.wm.getMostRecentWindow('navigator:browser'), 'Pick directory the icon container file should be saved in', Ci.nsIFilePicker.modeOpen);
// fp.appendFilters(Ci.nsIFilePicker.filterAll);
var rv = fp.show();
if (rv == Ci.nsIFilePicker.returnOK || rv == Ci.nsIFilePicker.returnReplace) {
console.log('path to selected file:', fp.file.path);
}// else { // cancelled }
You need to:
1.) include image in the addon (under data folder) ex: data\image\panelimg.jpg
2.) in the panel.html file, you will reference img by it's relative path in reference to html file. ex:
You can only reference assets bundled with the add-on (and not any image in file system)
This is difficult to explain. I needed some fills in Coreldraw that I liked and saved as SVG. When Coreldraw saved my svg, I got one folder called soil_Images with soil_ImgID1.png inside and soil.svg. And I put inside of web-app/images project. For some reason, the image png is not shown.
I have my svg like in my gsp:
<image x="177" y="76" width="36" height="23" preserveAspectRatio="none" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/projectName/images/soil.svg"></image>
And my soil.svg has another image tag that shows true image that I want:
<image x="44" y="29" width="8156" height="11707" xlink:href="soil_Images/soil_ImgID1.png"/>
I tried to add a contextpath like: ${application.contextPath}/images/soil_Images/soil_ImgID1.png.
That didn't work. What am I missing?
In chrome resources, the image hasn't been downloaded.
Building off of Matt Busche's blog post on using the asset pipeline with SVG and PNG fallback images, try pointing to the asset pipeline location instead of hardcoding. Note the assetPath with src (the relative path you are using if not the default asset pipeline image location) and the name of the image.
<image xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${assetPath(src: 'imgs/' + logoSVG)}" src="${assetPath(src: 'imgs/' + logoPNG)}"></image>
I have (java) code that generates PNG images from a custom infrared camera from time to time all the same size and, at the moment, just saves them outside the server space. They all have the same name and the most recent overwrites the previous one.
I can send a message to my dart code in the browser that an image is available for automatic loading for display in an image element.
Should I create an image folder and save them there?
How would the browser request and display the image? I'm using port 4955 for html.
I'm new at dart, html etc.
<-- edit -->
Will this allow me to change the DOM?
HTML
<div id='image-div'>
<img alt='' id='image' src='resources/200C-B12.png'
height='480' width='640'>
</div>
CSS
#image {
}
Dart
ImageElement imageElement = querySelector('#image');
I think I want to change the above ImageElement to this the below but don't know how.
"<img alt='' id='image' src='imageDisplay/myimage.png'
height='480' width='640'>";
<-- edit -->
I have tried the suggested methods to request the image but none works. The most recent attempt is below. I have a statement that writes to a log-file in the Dart server code that handles HTTP requests and, while there are log entries made when the page page is loaded there are none when I try to request a different image. The client page does receive the correct path to the image so the problem is that I still don't grok the correct procedure.
HTML currently - want to replace src ... to src='displayImage/some_image.png'
<div id='img-box'>
<div id='image-div'>
<div id='imgAnchor'>
<img alt='' id='image' src='resources/fi_12_demo.png'
height='480' width='640'>
</div>
</div>
</div>
Dart code fragment:
void displayNewImage(imagename) {
updateLog('display image = $imagename'); // imagename is correct
var anchor = querySelector('#imgAnchor');
anchor.children.clear;
anchor.append(new ImageElement()
..innerHtml="<img alt='' id='image' src='$imagename' height='480px' width='640px'>");
}
I conclude that no request is being sent from the client to my Dart server.
I think adding an <img src="http://yourserver.yourdomain.com:4955/somefolder/someimg.png"> to your HTML dynamically (by Dart code) should do. If the updated images have the same name you might run into caching issues (the browser doesn't load the image from the server but loades it from the cache instead). It might be easier to store each image with a new name.
I'm using ASP.NET MVC and have a model which has an image (byte array) in one of the fields. I'm trying to output this image into the src attribute of the img tag. I'm looking to do something like <img src='<%= Model.VenueImage %>'>. How can I do this?
Maybe Inline Images with Data URLs idea?
Inline images use the data URI scheme
to embed images directly within web
pages. As defined by RFC 2397, data
URIs are designed to embed small data
items as "immediate" data, as if they
were referenced externally. Using
inline images saves HTTP requests over
externally referenced objects.
System.Drawing.Image image = GetImageFromSomewhere(...);
byte[] imageData = ImageToByteArray(image);
string imageBase64 = Convert.ToBase64String(imageData);
string imageSrc = string.Format("data:image/gif;base64,{0}", imageBase64);
and then somewhere in the page:
<img src= "<%= ImageSrcBytes %>" />
AFAIK this will work for Opera 7.2+, Firefox, Safari, Netscape, Mozilla and IE8+ (IE8 up to 32kb).
For earlier version of IE there is a workaround - MHTML.
The example how to do it is here.
The browser uses the src attribute to issue a separate request to the server, to get the contents of the image. It does not display the bytes in the src as the image itself.
So you will need to remember those bytes (session?) and use a handler (the url you put into the src attribute) to let the browser request them.