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_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 1442 to 1493

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 14th December 2024 20:35 Europe/London time based on the source file dated 28th May 2024 16:20 Europe/London time.