Scraping High-Res images from the MoMA and the Van Gogh Museum websites
MoMA
res
= {1,2,3..} is the resolution.Use res = -1
for the max available resolution, but beware of a shipload of lawyers, middle managers, telephone sanitisers and hairdressers that may try to prosecute you if you use a value greater than 1
,
moma[catalogueNumber_, res_] :=
Module[{m = "http://www.moma.org", src, sj, rep, exp, a},
rep = {"]" -> "}", "[" -> "{"};
exp = Shortest["allImageTiles =" ~~ a : __ ~~ ";"] -> a;
src = Import[StringJoin[m, "/collection/works/", ToString@catalogueNumber], "Source"];
sj = Map[Import[m <> #] &, (ToExpression@
StringReplace[StringCases[src, exp], rep])[[1,1,res]], {2}];
ImageAssemble@Transpose@sj]
moma[60110, 1]
Van Gogh Museum
Here is the same for the tiles structure of the Van Gogh Museum at @bills' request. Note that the structure is completely different. I preserved the same resolution convention:
vanInTheSkyWithLucy[catalog_, res_] :=
Module[{i, df, zooms, c, maxXY, t},
i = Import["http://www.vangoghmuseum.nl/en/collection/" <> catalog, "XMLObject"];
df = First@ Cases[i, XMLElement[__, {___, "data-url" -> a__, ___}, ___] -> a, ∞];
zooms = Reverse["levels" /. Import[df, "JSON"]];
If [$VersionNumber >= 10,
c = Cases[#, {"x" -> x_, "y" -> y_, "url" -> u_} :>{x, y, u},∞],
c = Cases[#, {"url" -> u_, "x" -> x_, "y" -> y_} :>{x, y, u},∞]] &@zooms[[res]];
maxXY = Max /@ (Transpose[c][[;; 2]]) + 1;
t = ConstantArray[1, Reverse@maxXY];
(t[[#[[2]] + 1, #[[1]] + 1]] = #[[3]]) & /@ c;
ImageAssemble@Map[Import, t, {2}]]
vanInTheSkyWithLucy["d0364V1968", 1]
Warning The code works differently on V9 and V10, so I added a version check.Thanks lot to @bills for the debugging! Apparently the JSON import works differently.