Created
October 17, 2016 08:46
-
-
Save cfitz/c1f7bf4f2832656acd384f0182e134c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'uri' | |
| require 'fileutils' | |
| require 'iiif/presentation' | |
| require 'json' | |
| collection = nil | |
| @base = "http://loris-dev.dlts.org/loris/" | |
| profile = {"profile"=>["http://iiif.io/api/image/2/level2.json", {"supports"=>["canonicalLinkHeader", "profileLinkHeader", "mirroring", "rotationArbitrary", "sizeAboveFull", "regionSquare"], "qualities"=>["default", "bitonal", "gray", "color"], "formats"=>["jpg", "png", "gif", "webp"]}]} | |
| tiles = [ {"width" => 1890, "scaleFactors" => [1,2,4,8,16,31] }] | |
| # first go through the img.txt and build the individual files.txt | |
| IO.read("imgs.txt").each_line do |line| | |
| line.chomp! | |
| puts line | |
| if line =~ /^\t/ | |
| line.gsub!("\t", "") | |
| path = URI(line).path | |
| col = path.split("/")[-2] | |
| file = path.split("/").last.gsub("s.jpg", "d.jp2") | |
| url = "#{@base}/#{col}%2F#{file}" | |
| File.open("data/#{collection}/files.txt", "a") { |f| f << url + "\n" } | |
| else | |
| collection = line.split("/").last | |
| FileUtils.mkdir("data/#{collection}") unless File.exists?("data/#{collection}") | |
| File.open("data/#{collection}/files.txt", "w") | |
| end | |
| end | |
| # now go through all the files and build out the manifests | |
| Dir.glob("data/**/files.txt").each do |file| | |
| puts file | |
| files = [] | |
| IO.read(file).each_line do |line| | |
| line.chomp! | |
| line.gsub!("loris//", "loris/") | |
| params = {service_id: line} | |
| img = JSON.parse IIIF::Presentation::ImageResource.create_image_api_image_resource(params).to_json | |
| img.merge!(profile) | |
| img["@context"] = "http://iiif.io/api/image/2/context.json" | |
| img["protocol"] = "http://iiif.io/api/image" | |
| img["tiles"]= tiles | |
| img["@id"] = line | |
| files << img | |
| end | |
| File.open("#{ File.dirname(file) }/files.json", 'w') { |f| f << JSON.pretty_generate(files) } | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment