Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test 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/iiif_functions.php lines 1357 to 1430

Definition

 
function iiif_get_canvases($identifier$iiif_results,$sequencekeys=false)
    {
    global 
$rooturl,$iiif_sequence_field;

    
$canvases = array();
    foreach (
$iiif_results as $index=>$iiif_result)
        {
        
$useimage $iiif_result;
        if ((int)
$iiif_result['has_image'] === 0)
            {
            
// If configured, try and use a preview from a related resource
            
debug("IIIF: No image for IIIF request - check for related resources");
            
$pullresource related_resource_pull($iiif_result);
            if(
$pullresource !== false)
                {
                
$useimage $pullresource;
                }
            }
        
$size is_jpeg_extension($useimage["file_extension"] ?? "") ? "" "hpr";
        
$img_path get_resource_path($useimage["ref"],true,$size,false);
        if(!
file_exists($img_path))
            {
            continue;
            }
        
$sequenceid $iiif_result["iiif_position"];
        
$sequence_field get_resource_type_field($iiif_sequence_field);
        
$sequence_prefix "";
        if (isset(
$GLOBALS["iiif_sequence_prefix"]))
            {
            
$sequence_prefix  $GLOBALS["iiif_sequence_prefix"] === "" $sequence_field["title"] . " " $GLOBALS["iiif_sequence_prefix"];
            }

        
$canvases[$index]["@id"] = $rooturl $identifier "/canvas/" $index;
        
$canvases[$index]["@type"] = "sc:Canvas";
        
$canvases[$index]["label"] = $sequence_prefix $sequenceid;

        
// Get the size of the images
        
$image_size get_original_imagesize($useimage["ref"],$img_path);
        
$canvases[$index]["height"] = intval($image_size[2]);
        
$canvases[$index]["width"] = intval($image_size[1]);

        
// "If the largest image's dimensions are less than 1200 pixels on either edge, then the canvas 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[$index]["thumbnail"] = iiif_get_thumbnail($useimage["ref"]);

        
// Add image (only 1 per canvas currently supported)
        
$canvases[$index]["images"] = array();
        
$size_info = array(
            
'identifier' => $size,
            
'return_height_width' => false,
        );
        
$canvases[$index]["images"][] = iiif_get_image($identifier$useimage["ref"], $index$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 15th December 2024 20:35 Europe/London time based on the source file dated 28th May 2024 16:20 Europe/London time.