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

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

array $return

Location

include/resource_functions.php lines 7919 to 8047

Definition

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

    
# Work out resource type
    
$resource_data get_resource_data($ref);
    
$resource_type $resource_data["resource_type"];

    
# add the original image
    
$return=array();
    
$lastname=ps_value("SELECT name value FROM preview_size WHERE width=(SELECT max(width) FROM preview_size)",[], "schema"); # Start with the highest resolution.
    
$lastpreview=0;$lastrestricted=0;
    
$path2=get_resource_path($ref,true,'',false,$extension);

    if(!
resource_has_access_denied_by_RT_size($resource_type'') && (file_exists($path2) || !$onlyifexists))
    {
        
$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"]="";
        
$returnline["original"] = 1;
        
$dimensions ps_query("select width,height,file_size,resolution,unit from resource_dimensions where resource=?",array("i",$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);
            if(
$fileinfo !== false)
                {
                
$filesize $fileinfo[0];
                
$sw$fileinfo[1];
                
$sh $fileinfo[2];
                }
            else
                {
                
$filesize $resource_data["file_size"];
                
$sw 0;
                
$sh 0;
                }
            }
        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=ps_query("SELECT " columns_in("preview_size") . " FROM preview_size ORDER BY width DESC", [],"schema");

    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
            && !
resource_has_access_denied_by_RT_size($resource_type$sizes[$n]['id'])
            && (
$sizes[$n]["internal"] == || $internal)
            ) {
                
$returnline=array();
                
$returnline["name"]=lang_or_i18n_get_translated($sizes[$n]["name"], "imagesize-");
                
$returnline["original"] = 0;
                
$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_unlimited($path) > 0)
                    {
                    
$filesize filesize_unlimited($path);
                    
$use_error_exception_cache $GLOBALS["use_error_exception"]??false;
                    
$GLOBALS["use_error_exception"] = true;
                    try
                        {
                        list(
$sw,$sh) = getimagesize($path);
                        }    
                    catch (
Exception $e)
                        {
                        
$sw=0;
                        
$sh=0;
                        }
                    
$GLOBALS["use_error_exception"] = $use_error_exception_cache;
                    }
                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 11th December 2024 19:05 Europe/London time based on the source file dated 11th December 2024 15:55 Europe/London time.