Collections functions
General 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 "thumbs"

Return

array array($width, $height, $margin);

Location

include/render_functions.php lines 2910 to 2973

Definition

 
function calculate_image_display($imagedata$img_url$display="thumbs")
    {
    if(
'' != $imagedata['thumb_width'] && != $imagedata['thumb_width'] && '' != $imagedata['thumb_height'])
        {
        
$ratio $imagedata["thumb_width"] / $imagedata["thumb_height"];   
        }
    else
        {
        
// use php function getimagesize()
        
$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 
"collection":
            
$defaultwidth 75;
            
$defaultheight 75;
        break;

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

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

    if (
$ratio 1)
        {
        
$width $defaultwidth;
        
$height round($defaultheight $ratio);
        
$margin floor(($defaultheight $height ) / 2);
        }
    elseif (
$ratio 1)
        {
        
# portrait image dimensions
        
$height $defaultheight;
        
$width round($defaultwidth $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 8th December 2023 03:35 Europe/London time based on the source file dated 29th November 2023 14:55 Europe/London time.