How to fix a dzproj file when DeepZoom Composer has mangled your CompositionNode’s Ids
Warning: if you’re not into building deepzoom systems, stop reading. This post will BORE YOU. Was the title not a good enough indication?
Ok good, they’re gone!
The current release of the deep zoom composer has a little bug. Ok – it has a few bugs, but I hate this one the most. You close your DeepZoom project(*.dzproj), you open your project, and viola – your images have rearranged themselves (or just disappeared). The first thing to worry about is: have you moved your files? Deepzoom projects store file references as absolute paths, which is ridiculous, but not the problem I was having.
Tori talks about this problem on the “known issues page” for the composer.
I don’t know what causes it (language settings were mentioned on that thread – I’m using en-NZ), but if you look inside the dzproj file itself, the Ids of all the composition nodes are all wrong.
More like “Deep Zoom Confounder”!
Im sure theres a fix coming, but if you’re as desperate as me, then what you’ve got to do is this:
1) put :<filename> on the end of each image’s tag
2) run the following code across your dzproj file:
using System;
using System.IO;
using System.Linq;
using System.Xml.Linq;
class Program
{
static void Main(string[] args)
{
var file = string.Join(" ", args);
XDocument d = XDocument.Load(file);
var images = from i in d.Descendants("Image")
select Path.GetFileName(i.Element("File").Value);
var imageList = images.ToList();
var map = from e in d.Descendants("CompositionNode")
let tag = e.Attribute("Tag")
where tag != null
let fileName = tag.Value.Split(':').Last()
where images.Contains(fileName)
select new
{
Node = e,
NewId = imageList.IndexOf(fileName)
};
foreach (var v in map)
{
v.Node.SetAttributeValue("Id", v.NewId);
}
d.Save(file);
Console.Out.WriteLine("Press any key to continue");
Console.ReadKey();
}
}
This code will read in the xml, build a list of all the correct image ids, then update the ids of all your composition. Its not easy, but it’s a workaround!
