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

calculate_image_display()

Description

Calculations width, height and margin-top property for resource image to display in ResourcePanel

Parameters

ColumnTypeDefaultDescription
$imagedata array
$img_url string
$display string
positive-int, array{'thumb_width': 'thumb_height': positive-int} $imagedata

Return

array Returns a tuple of width, height and margin

Location

include/render_functions.php lines 2928 to 2995

Definition

 
function calculate_image_display(array $imagedatastring $img_urlstring $display="thumbs"): array
    {
    if(
        
'' != $imagedata['thumb_width']
        && 
'' != $imagedata['thumb_height']
        && 
$imagedata['thumb_width'] > 0
        
&& $imagedata['thumb_height'] > 0
    
)
        {
        
$ratio $imagedata["thumb_width"] / $imagedata["thumb_height"];   
        }
    else
        {
        
$size $img_url != "" getimagesize($img_url) : [];
        
$ratio = isset($size[0]) ? $size[0] / $size[1] : 1;
        }
    
    switch(
$display)
        {
        case 
"xlthumbs":
            
$defaultwidth 320;
            
$defaultheight 320;
            break;

        case 
"thumbs":
            
$defaultwidth 200;
            
$defaultheight 200;
            break;

        case 
"list":
            
$defaultwidth 40;
            
$defaultheight 40;
            break;

        case 
"col":
            
$defaultwidth $imagedata['thumb_width'];
            
$defaultheight $imagedata['thumb_height'];
            break;

        default:
            
$defaultwidth 75;
            
$defaultheight 75;
            break;
        }

    if (
$ratio 1)
        {
        
$width $defaultwidth;
        
$height round($defaultwidth $ratio);
        
$margin floor(($defaultheight $height ) / 2);
        }
    elseif (
$ratio 1)
        {
        
# portrait image dimensions
        
$height $defaultheight;
        
$width round($defaultheight $ratio);
        
$margin floor(($defaultheight $height ) / 2);
        }
    else
        {
        
# square image or no image dimensions
        
$height $defaultheight;
        
$width $defaultwidth;
        
$margin "auto";
        }

    return array(
$width$height$margin);
    }

This article was last updated 4th December 2024 08:35 Europe/London time based on the source file dated 3rd December 2024 11:55 Europe/London time.