Collections functions
Encryption functions
General functions
Theme permission 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 2470 to 2528

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 175;
            
$defaultheight 175;
        break;        
        
        case 
"collection":
            
$defaultwidth 75;
            
$defaultheight 75;
        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 12th July 2020 01:35 Europe/London time based on the source file dated 8th July 2020 11:40 Europe/London time.