Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

iiif_get_canvases()

Description

Get an array of all the canvases for the identifier ready for JSON encoding

Parameters

ColumnTypeDefaultDescription
$identifier integer IIIF identifier (this associates resources via the metadata field set as $iiif_identifier_field
$iiif_results array Array of ResourceSpace search results that match the $identifier, sorted
$sequencekeys boolean false Get the array with each key matching the value set in the metadata field $iiif_sequence_field. By default the array will be sorted but have a 0 based index

Return

array

Location

include/api_functions.php lines 163 to 219

Definition

 
function iiif_get_canvases($identifier$iiif_results,$sequencekeys=false)
    {
    global 
$rooturl,$rootimageurl;    
            
    
$canvases = array();
    foreach (
$iiif_results as $iiif_result)
        {
        
$size = (strtolower($iiif_result["file_extension"]) != "jpg") ? "hpr" "";
        
$img_path get_resource_path($iiif_result["ref"],true,$size,false);

        if(!
file_exists($img_path))
            {
            continue;
            }
            
        
$position $iiif_result["iiif_position"];
        
$canvases[$position]["@id"] = $rooturl $identifier "/canvas/" $position;
        
$canvases[$position]["@type"] = "sc:Canvas";
        
$canvases[$position]["label"] = (isset($position_prefix)?$position_prefix:'') . $position;
        
        
// Get the size of the images
        
$image_size get_original_imagesize($iiif_result["ref"],$img_path);
        
$canvases[$position]["height"] = intval($image_size[2]);
        
$canvases[$position]["width"] = intval($image_size[1]);
                
        
// "If the largest image�s dimensions are less than 1200 pixels on either edge, then the canvas�s dimensions should be double those of the image." - From http://iiif.io/api/presentation/2.1/#canvas
        
if($image_size[1] < 1200 || $image_size[2] < 1200)
            {
            
$image_size[1] = $image_size[1] * 2;
            
$image_size[2] = $image_size[2] * 2;
            }
        
        
$canvases[$position]["thumbnail"] = iiif_get_thumbnail($iiif_result["ref"]);
        
        
// Add image (only 1 per canvas currently supported)
        
$canvases[$position]["images"] = array();
        
$size_info = array(
            
'identifier' => $size,
            
'return_height_width' => false,
        );
        
$canvases[$position]["images"][] = iiif_get_image($identifier$iiif_result["ref"], $position$size_info);
        }
    
    if(
$sequencekeys)
        {
        
// keep the sequence identifiers as keys so a required canvas can be accessed by sequence id
        
return $canvases;
        }
    
    
ksort($canvases);    
    
$return=array();
    foreach(
$canvases as $canvas)
        {
        
$return[] = $canvas;
        }
    return 
$return;
    }

This article was last updated 7th July 2020 10:35 Europe/London time based on the source file dated 25th June 2020 16:08 Europe/London time.