Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

get_image_sizes()

Description

Returns a table of available image sizes for resource $ref. The standard image sizes are translated using $lang. Custom image sizes are i18n translated.
The original image file assumes the name of the 'nearest size (up)' in the table

Parameters

ColumnTypeDefaultDescription
$ref int ID of resource
$internal boolean false
$extension string "jpg" File extension of image
$onlyifexists boolean true

Return

void

Location

include/resource_functions.php lines 7159 to 7264

Definition

 
function get_image_sizes($ref,$internal=false,$extension="jpg",$onlyifexists=true)
    {
    global 
$imagemagick_calculate_sizes;

    
# Work out resource type
    
$resource_type=sql_value("select resource_type value from resource where ref='$ref'","");

    
# add the original image
    
$return=array();
    
$lastname=sql_value("select name value from preview_size where width=(select max(width) from preview_size)",""); # Start with the highest resolution.
    
$lastpreview=0;$lastrestricted=0;
    
$path2=get_resource_path($ref,true,'',false,$extension);

    if (
file_exists($path2) && !checkperm("T" $resource_type "_"))
    { 
        
$returnline=array();
        
$returnline["name"]=lang_or_i18n_get_translated($lastname"imagesize-");
        
$returnline["allow_preview"]=$lastpreview;
        
$returnline["allow_restricted"]=$lastrestricted;
        
$returnline["path"]=$path2;
        
$returnline["url"] = get_resource_path($reffalse""false$extension);
        
$returnline["id"]="";
        
$dimensions sql_query("select width,height,file_size,resolution,unit from resource_dimensions where resource='" escape_check($ref) . "'");
        
        if (
count($dimensions))
            {
            
$sw $dimensions[0]['width']; if ($sw==0) {$sw="?";}
            
$sh $dimensions[0]['height']; if ($sh==0) {$sh="?";}
            
$filesize=$dimensions[0]['file_size'];
            
# resolution and unit are not necessarily available, set to empty string if so.
            
$resolution = ($dimensions[0]['resolution'])?$dimensions[0]['resolution']:"";
            
$unit = ($dimensions[0]['unit'])?$dimensions[0]['unit']:"";
            }
        else
            {
            
$fileinfo=get_original_imagesize($ref,$path2,$extension);
            
$filesize $fileinfo[0];
            
$sw $fileinfo[1];
            
$sh $fileinfo[2];
            }
        if (!
is_numeric($filesize)) {$returnline["filesize"]="?";$returnline["filedown"]="?";}
        else {
$returnline["filedown"]=ceil($filesize/50000) . " seconds @ broadband";$returnline["filesize"]=formatfilesize($filesize);}
        
$returnline["width"]=$sw;           
        
$returnline["height"]=$sh;
        
$returnline["extension"]=$extension;
        (isset(
$resolution))?$returnline["resolution"]=$resolution:$returnline["resolution"]="";
        (isset(
$unit))?$returnline["unit"]=$unit:$returnline["unit"]="";
        
$return[]=$returnline;
    }
    
# loop through all image sizes
    
$sizes=sql_query("select * from preview_size order by width desc");
    
    for (
$n=0;$n<count($sizes);$n++)
        {
        
$path=get_resource_path($ref,true,$sizes[$n]["id"],false,"jpg");

        
$file_exists file_exists($path);
        if ((
$file_exists || (!$onlyifexists)) && !checkperm("T" $resource_type "_" $sizes[$n]["id"]))
            {
            if ((
$sizes[$n]["internal"]==0) || ($internal))
                {
                
$returnline=array();
                
$returnline["name"]=lang_or_i18n_get_translated($sizes[$n]["name"], "imagesize-");
                
$returnline["allow_preview"]=$sizes[$n]["allow_preview"];

                
# The ability to restrict download size by user group and resource type.
                
if (checkperm("X" $resource_type "_" $sizes[$n]["id"]))
                    {
                    
# Permission set. Always restrict this download if this resource is restricted.
                    
$returnline["allow_restricted"]=false;
                    }
                else
                    {
                    
# Take the restriction from the settings for this download size.
                    
$returnline["allow_restricted"]=$sizes[$n]["allow_restricted"];
                    }
                
$returnline["path"]=$path;
                
$returnline["url"] = get_resource_path($reffalse$sizes[$n]["id"], false"jpg");
                
$returnline["id"]=$sizes[$n]["id"];
                if (
$file_exists)
                    {
                    
$filesize filesize_unlimited($path);
                    list(
$sw,$sh) = getimagesize($path);  
                    }
                else
                    {
                    
$filesize=0;
                    
$sw=0;
                    
$sh=0;
                    }

                if (
$filesize===false) {$returnline["filesize"]="?";$returnline["filedown"]="?";}
                else {
$returnline["filedown"]=ceil($filesize/50000) . " seconds @ broadband";$filesize=formatfilesize($filesize);}
                
$returnline["filesize"]=$filesize;          
                
$returnline["width"]=$sw;           
                
$returnline["height"]=$sh;
                
$returnline["extension"]='jpg';
                
$return[]=$returnline;
                }
            }
        
$lastname=lang_or_i18n_get_translated($sizes[$n]["name"], "imagesize-");
        
$lastpreview=$sizes[$n]["allow_preview"];
        
$lastrestricted=$sizes[$n]["allow_restricted"];
        }
    return 
$return;
    }

This article was last updated 29th November 2020 04:05 Europe/London time based on the source file dated 27th November 2020 14:50 Europe/London time.