Gallica Clips Converter

Did your links to Gallica clipped images stop working like mine?

Last updated on May 29, 2016, by Jesse Hurlbut

In October 2015, when Gallica changed the format of the URL used to insert a clipped image from one of their pages into our own blog posts, I was worried that my old-format pages would look like this:

GallicaBrokenImages

I was pleased to see that my clipped images remained after the change-over. I had clipped over 2000 images using the old system over the course of years and I really didn’t want to have to re-clip them all.

Relief turned to chagrin in May 2016, when suddenly, all clipped links created before the change disappeared, leaving broken image links on both summary pages and on individual posts. Attempting to use the old-format URLs resulted in an Internal Server 500 error. I started hunting for a conversion utility that would automate the transformation of my old clipped URLs to the new ones. Here’s what needed to be done:

Old URL:

http://gallica.bnf.fr/proxy?method=R&ark=btv1b84511055.f640&l=5&r=3580,4016,389,786

New URL:

http://gallica.bnf.fr/iiif/ark:/12148/btv1b84511055/f640/4016.303871624745,3580.217745617651,1572.0355025258591,778.5160865107023/786,389/0/native.jpg

After some reverse engineering of the coordinate system in each, I was able to generate a simple program that automatically converted all my broken links in about 1 second. The basis for the transformation is a single perl regex string replacement command (s///), but which gets iterated for each of the levels of zoom. Here is the basic solution:

s/src=("|'')(http:\/\/gallica\.bnf\.fr\/)proxy\?method=R&ark=(b\w+)\.(f\d+)&l=6&r=(\d+),(\d+),(\d+),(\d+)("|'')/src="$2iiif\/ark:\/12148\/$3\/$4\/$6,$5,$8,$7\/$8,$7\/0\/native.jpg"/g

In the end, I exported the table of my web site database that included all of these broken references to a text-readable SQL file. I made a copy of the file named ‘old-Gallica’ then I ran the program, which created a new file named ‘new-Gallica’ with all the URLs repaired. Then I re-installed the table to my web database. So far, out of more than 2000 repairs, I have found only two images that didn’t convert correctly (I may yet find more). I have simply re-clipped those, and all seems to be working very well.

If you need to convert your collection of broken Gallica clipped image URLs, you may want to try this code for yourself. It’s written in perl, which is well-suited for this kind of string conversion. Prepare a text file with the URLs to update, download the perl script, and run it. The program is not destructive, but creates a new file with all the new URLs. Nevertheless, exporting and importing database tables should be undertaken by someone confident in the procedure since that can cause a whole web site to crash if done incorrectly. Always prepare backups in case you need to restore an old version of the site. Specific instructions are inside the comments of the program file itself. There’s really not much to it.

Download script: https://github.com/toisondor/GallicaURLconversion

 

Here is my site after the repair:

GallicaFixed

Back to normal!!