Page 1 of 1

Reaction in extension scripts when image does not exist

Posted: 02 Feb 2022, 01:00
by Joerg Hamacher
When expanding the displays with images, I put together the file names of the images from fields on the screen, here e.g. from DLART1 and DLVEL1.
The image file has the extension .tif - at least for now.
Now I get pictures both as .tif and as .jpg and would have to search alternatively, so to speak, once for DLART+DLVEL.tif and (if no result) again with DLART+DLVEL.jpg. Can this be controlled in the script?
CLIP-6B2C2B6C.JPG
CLIP-6B2C2B6C.JPG (24.34 KiB) Viewed 4822 times
Now there should be a reaction if the image in w_ImageName does not exist.
In this case I want to to use ".jpg" instead of ".tif".
Can this be done in aXes scripts?

Many thanks in advance and best regards,
Joerg

Re: Reaction in extension scripts when image does not exist

Posted: 03 Feb 2022, 10:47
by Dino
Hi Joerg,

The next script works fine to identify if a file exist in a url. you just need to provide the relative path to the image, as the image is not located in the same folder as the script, and off course, before returning your final decision about what file to use, use the verifyFile() function to check if the file exist:

Code: Select all

function verifyFile(urlToFile) {
    var abc = new XMLHttpRequest();
    abc.open('HEAD', urlToFile, false);
    abc.send();
    if (abc.status == "404") { return false; } else { return true;  }
}
 
// Testing the verifyFile function
var result = verifyFile("/ts/skins/images/examplephoto.gif");
if (result == true)  alert('The file exist!'); else alert('sorry, not here!');

Re: Reaction in extension scripts when image does not exist

Posted: 03 Feb 2022, 18:54
by Joerg Hamacher
Hi Dino,

thank you very much for this example.

Best regrads,
Joerg