Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource 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 2841 to 2908

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 21st May 2024 21:35 Europe/London time based on the source file dated 17th May 2024 16:45 Europe/London time.