iiif_get_thumbnail()

Description

Get thumbnail information for the specified resource id ready for IIIF JSON encoding

Parameters

ColumnTypeDefaultDescription
$resourceid integer Resource ID

Return

array

Location

include/iiif_functions.php lines 1291 to 1336

Definition

 
function iiif_get_thumbnail($resourceid)
{
    global 
$rootimageurl;

    
$img_path get_resource_path($resourceidtrue'thm'false);
    if (!
file_exists($img_path)) {
        
// If configured, try and use a preview from a related resource
        
$resdata get_resource_data($resourceid);
        
$pullresource related_resource_pull($resdata);
        if (
$pullresource !== false) {
            
$resourceid $pullresource["ref"];
            
$img_path get_resource_path($resourceidtrue"thm"false);
        }
    }

    if (!
file_exists($img_path)) {
        return 
false;
    }

    
$thumbnail = array();
    
$thumbnail["@id"] = $rootimageurl $resourceid "/full/thm/0/default.jpg";
    
$thumbnail["@type"] = "dctypes:Image";

    
// Get the size of the images
    
$GLOBALS["use_error_exception"] = true;
    try {
        list(
$tw,$th) = getimagesize($img_path);
        
$thumbnail["height"] = (int) $th;
        
$thumbnail["width"] = (int) $tw;
    } catch (
Exception $e) {
        
$returned_error $e->getMessage();
        
debug("getThumbnail: Unable to get image size for file: $img_path  -  $returned_error");
        
// Use defaults
        
$thumbnail["height"] = 150;
        
$thumbnail["width"] = 150;
    }
    unset(
$GLOBALS["use_error_exception"]);

    
$thumbnail["format"] = "image/jpeg";

    
$thumbnail["service"] = array();
    
$thumbnail["service"]["@context"] = "http://iiif.io/api/image/2/context.json";
    
$thumbnail["service"]["@id"] = $rootimageurl $resourceid;
    
$thumbnail["service"]["profile"] = "http://iiif.io/api/image/2/level1.json";
    return 
$thumbnail;
}

This article was last updated 12th May 2025 21:35 Europe/London time based on the source file dated 4th April 2025 15:35 Europe/London time.