From 6adcaabed012589308aa118cac5a78a6b0c0a199 Mon Sep 17 00:00:00 2001 From: dleadbetter Date: Mon, 28 Oct 2024 11:42:44 -0400 Subject: [PATCH] Archnet #1216 - Updating "convert" service to use RGB colorspace; Adding "convert_images_by_colorspace" rake task --- app/services/images/convert.rb | 2 ++ lib/tasks/iiif.rake | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/app/services/images/convert.rb b/app/services/images/convert.rb index 89326a2..d1cef79 100644 --- a/app/services/images/convert.rb +++ b/app/services/images/convert.rb @@ -18,6 +18,8 @@ def self.to_tiff(file) convert << 'jpeg' convert << '-alpha' convert << 'remove' + convert << '-colorspace' + convert << 'sRGB' convert << "ptif:#{output_path}" convert.call diff --git a/lib/tasks/iiif.rake b/lib/tasks/iiif.rake index 49ba7cb..3f04af5 100644 --- a/lib/tasks/iiif.rake +++ b/lib/tasks/iiif.rake @@ -34,6 +34,33 @@ namespace :iiif do end end + desc '' + task convert_images_by_colorspace: :environment do + # Parse the arguments + options = {} + + opt_parser = OptionParser.new do |opts| + opts.banner = 'Usage: rake iiif:convert_images_by_colorspace [options]' + opts.on('-c', '--colorspace ARG', 'Image colorspace') { |colorspace| options[:colorspace] = colorspace } + end + + args = opt_parser.order!(ARGV) {} + opt_parser.parse!(args) + + if options[:colorspace].blank? + puts 'Please specify a colorspace...' + exit 0 + end + + query = Resource.where("(exif::json)->>'colorspace' = ?", options[:colorspace]) + + query.in_batches do |resources| + resources.pluck(:id).each do |resource_id| + ConvertImageJob.perform_later(resource_id) + end + end + end + desc 'Converts the source images to pyramidal TIFFs for resources by the specified MIME type' task convert_images_by_type: :environment do # Parse the arguments