Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

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 1398 to 1449

Definition

 
function iiif_get_thumbnail($resourceid)
    {
    global 
$rootimageurl;

    
$img_path get_resource_path($resourceid,true,'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($resourceid,true,"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 19th March 2024 08:35 Europe/London time based on the source file dated 8th March 2024 15:10 Europe/London time.