|Syntactic Confectionery Delight|
Include Inline Image in HTMLby Anonymous Monk
|on Jan 03, 2011 at 21:44 UTC||Need Help??|
Anonymous Monk has asked for the
wisdom of the Perl Monks concerning the following question:
Thanks for providing this site. Great information here, always!
Would someone know if it is possible to include the binary data for a jpeg directly in HTML (create an inline image). Here is why I ask:
We have an in-house created Perl application on a Linux server that creates a MS Word doc simply by send HTML to the browser and setting the MIME type of the page to "application/msword". Everyone in the company uses IE and has MS Word installed on their workstation, so doing this has not been a problem. When the HTML is sent to the browser, a prompt displays to the user to download the Word doc.
The HTML contains image tags. The source for each image is a cgi page that retrieves the binary data for the image from a database and prints it to output as MIME type "image/jpeg". The image tags look something like this then:<img src="https://subdomain.ourserver.com/showimage.cgi/00000000000.jpg" />
This worked great for all versions of Word until Word 2007. The Word doc still generates just fine. However, images within the doc do not display. We have determined that this may be due to a GPO that blocks anything that Word considers to be external content. Even though the URL to the image resides within the company intranet, Word security seems to still block it. We cannot get a change to this GPO. We also cannot seem to modify Word settings to trust the URL for the image. Googling shows that many people are experiencing this issue with Word 2007 and there does not seem to be a solution aside from embedding the image in Word after the document has been created.
Embedding the image after the fact would be inconvenient for the users to do, so we are trying to find a way to force Word to see the image as embedded at the time the document is created. We thought that if we could add the binary data for the image somehow directly to the page that generates the HTML, that might resolve the issue. But we are stuck trying to figure out how to send two different MIME types - the one for the main document and then the one for each image that is written to the document. None of us are well versed in Perl and so don't know how it can be done, if at all. Also, we need to be able to do it in a loop as more than one record with binary image data will need to be written to the doc.
Thanks in advance for any information you are able to provide. Please let me know if you need more info from me.