« What a conference ... Main | Barcodes barcodes barcodes ... which ones to pick? »

Dynamic Images

Made it back from Nashville with a pile of requests for blog entries, I'll try and cover them over the next few weeks ... top of the list of requests was how to handle dynamic images in a layout template. There are several ways to tackle this depending on where your images are going to be at runtime. The scenario is, that I have three organizations in my company and they each have their own logo; at runtime, based on the organization I am generating a report for the output should show their logo. Lets assume we have the following XML data for all of these examples:


<INVOICELIST>
 <IMG_DIR>/images</IMG_DIR>
 <IMG_SERVER>http://xdo.us.oracle.com</IMG_SERVER>
 <IMG_DIR_PATH>c:temp</IMG_DIR_PATH>
 <G_VENDOR_NAME>
  <ORG>1</ORG>
  <IMGFILE>Org1.gif</IMGFILE>
  <VENDOR_NAME>Nuts and Bolts Limited</VENDOR_NAME>
  <ADDRESS>1 El Camino Real, Redwood City, CA 94065</ADDRESS>
   <G_INVOICE_NUM>
    <SET_OF_BOOKS_ID>124</SET_OF_BOOKS_ID>
    <GL_DATE>10-NOV-04</GL_DATE>
    ...
 </G_VENDOR_NAME>
 <G_VENDOR_NAME>
  <ORG>2</ORG>
  <IMGFILE>Org2.gif</IMGFILE>
  <VENDOR_NAME>Tick Tock Clocks</VENDOR_NAME>
  ...
</INVOICELIST>


So our XML references an image directory(IMG_DIR) on our server(IMG_SERVER) and the full path to the image directory (IMG_DIR_PATH) on our server, then each invoice has the organization ID and the image name to be used. So we can tackle this one of three ways:
1. Embed the three logos into the template directly
2. Reference the images on the disk and use a dynamic image
3. Reference the images via a URL


Embedding in the template


This is the simplest method, if we have three images, one for each organization we can add them all to the template and wrap them in conditional statements to show/hide them. 

DynImg1:

The simplest method is to use three 'if' statements, you could equally use a 'choose' statement to get the same effect. See DynamicImg1.rtf template here. If you have alot of images and/or need dynamic images in multiple templates; you could put a template function either else where in the template or ina completely separate template altogether and then call it from the main templates. See DynamicImg2.rtf for an example in the zip file


Using dynamic images


We can also just add a single dummy image to the template and at runtime point to the correct image file either on the file system or via a URL. We can build the file location of the image quite easily using the XSL concat() function.  Note at runtime the incoming image will be resized (if necessary) to fit the same dimensions as the dummy image.
So in the Web tab of the image properties we have:

DynImg2:

File System: url:{concat(../IMG_DIR_PATH,'/',IMGFILE)} See DynamicImg3.rtf
URL: url:{concat(../IMG_SERVER,'/',../IMG_DIR,'/',IMGFILE)} See DynamicImg4.rtf


Notice we use '../' to get a level up from the G_VENDOR_NAME level for the root level values we need to construct the path or URL i.e. ../IMG_DIR_PATH.


If you are an E Business Suite user you can also make use of the OA_MEDIA directory. XML Publisher will resolve this value at runtime. So for an image in the OA_MEDIA directory you could use:


url:{?${OA_MEDIA}/IMGFILE?}


You can get all the examples and XML data here.
So thats dynamic images, of course you can use it for any image and you can build much more complex conditional formatting rules around the images. Have a good day ...

Comments (6)

Tim Dexter:

Hi Justin
Check the user guide it covers how to use parameters to pass a URL reference of an image to a template.
Regards, Tim

Very useful tip here Tim, and I suspect we'll be using a combination of all of them here at some point. Thanks!

abhishek paliwal:

Hi all,
I want to use OA_MEDIA directory. In my xml i have a tag IMAGE which will give the image name available in OA_MEDIA directory.
and in rtf i am inserting a dummy image. And writing the following syntex in web section:
url:('${OA_MEDIA}','/',IMAGE)
But now also i am not getting image in the PDF Output.
But if i give complete path in my xml file under IMAGE tag and in rtf i write url:(IMAGE) i am getting images.
Please can anybody help me in this case.
It would be better if provide me one sample rdf and rtf with OA_MEDIA directory example.

Thanks
Abhishek paliwal

Tim:

Abhishek
This is better asked on the Publisher forum on OTN

Tommy:

Hi,
I want to include a .svg-picture from a xml-source, the xml tag is:

<Q14_ADRESSE>
http://server/picture.svg?par_1=51859&par2=&par3=1&par4=1&par5=407749
</Q14_ADRESSE>

so I have many different pictures generated from another programm and I have only this tag.
I woud prefer to do this with MSword, so I need a funktion. Another problem is, that MSword can't do .svg ... so I'm in trouble

can someone help me?
thanks

Guney:

Hi all,
Before I start, many thanks for your deserving tutorial about dynamic image.

I am very new on Xml Publisher and for a week, I have tried adding dynamic image in my reports. According to your statement
that means Reference the images via a URL.

I have created a XML element and put my image location in that tags, after that I've created an dummy image in my rtf file and changed this web alternative text properties according to format you mention above and also I have give full path in only one xml element but unfortunately the image doesnt appear im my output file.But when I ve used first method "Embedding image in the template", the image appears.

Also I ve tried your examples data but the image again doesnt appears if I used Reference the images via a URL technique.

Can you or anyone help me ?
thank

Post a comment