app/services/spotlight/upload_solr_document_builder.rb
# Creates thumbnails for different types of resources and adds the link to thumbnail_url_ssm in solr hash
Creates thumbnails for different types of resources and adds the link to thumbnail_url_ssm in solr hash
Creates thumbnails for different types of resources and adds the link to thumbnail_url_ssm in solr hash
def add_file_versions(solr_hash)
      file_path = "public/uploads/spotlight/featured_image/image/#{resource.upload_id}/#{resource.file_name}"
      if resource.file_type == "image"
        solr_hash[Spotlight::Engine.config.thumbnail_field] = riiif.image_path(resource.upload_id, size: '!400,400')
      elsif resource.file_type == "compound object"
        solr_hash[Spotlight::Engine.config.thumbnail_field] = riiif.image_path(first_resource(resource).upload_id, size: '!400,400')
      elsif resource.file_type == "pdf"
        first_page = CombinePDF.load(file_path).pages[0]
        pdf_name = resource.file_name.split(".").first
        new_pdf = CombinePDF.new
        new_pdf << first_page
        dirname = File.dirname(file_path)
        first_page_path = "#{dirname}/#{pdf_name}-cover.pdf"
        new_pdf.save first_page_path
        image = PDFToImage.open(first_page_path).first.resize("50%").save("#{dirname}/#{pdf_name}-thumb.jpeg")
        solr_hash[Spotlight::Engine.config.thumbnail_field] = "#{file_path.sub!("public","").sub!("#{resource.file_name}","/#{pdf_name}-thumb.jpeg")}"
      else 
        files = Dir.entries(file_path)
        unless files.any? { |f| f.include? "jpeg" }
          featured_image = resource.upload
          featured_image.image.recreate_versions!
        end
      end
    end
def add_file_versions ( solr_hash ) file_path = "public/uploads/spotlight/featured_image/image/#{resource.upload_id}/#{resource.file_name}" if resource . file_type == "image" solr_hash [ Spotlight :: Engine . config . thumbnail_field ] = riiif . image_path ( resource . upload_id , size : '!400,400' ) elsif resource . file_type == "compound object" solr_hash [ Spotlight :: Engine . config . thumbnail_field ] = riiif . image_path ( first_resource ( resource ) . upload_id , size : '!400,400' ) elsif resource . file_type == "pdf" first_page = CombinePDF . load ( file_path ) . pages [ 0 ] pdf_name = resource . file_name . split ( "." ) . first new_pdf = CombinePDF . new new_pdf << first_page dirname = File . dirname ( file_path ) first_page_path = "#{dirname}/#{pdf_name}-cover.pdf" new_pdf . save first_page_path image = PDFToImage . open ( first_page_path ) . first . resize ( "50%" ) . save ( "#{dirname}/#{pdf_name}-thumb.jpeg" ) solr_hash [ Spotlight :: Engine . config . thumbnail_field ] = "#{file_path.sub!("public","").sub!("#{resource.file_name}","/#{pdf_name}-thumb.jpeg")}" else files = Dir . entries ( file_path ) unless files . any? { | f | f . include? "jpeg" } featured_image = resource . upload featured_image . image . recreate_versions! end end end
Creates thumbnails for different types of resources and adds the link to thumbnail_url_ssm in solr hash
Creates thumbnails for different types of resources and adds the link to thumbnail_url_ssm in solr hash
# File.delete(first_page_path) # if resource.file_type = "video" # Generate thumbnail unless it already has one # See uploaders/featured_image_uploader.rb
solr_hash