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

get_resource_all_image_sizes()

Description

Return all sizes available for a specific resource. Multi page resources should have each page size included as well
in the output.

Parameters

ColumnTypeDefaultDescription
$ref integer Resource ID

Return

array

Location

include/resource_functions.php lines 6906 to 6972

Definition

 
function get_resource_all_image_sizes($ref)
    {
    if(
get_resource_access($ref) !== 0)
        {
        return array();
        }

    
$resource_data get_resource_data($reftrue);
    if(
$resource_data["file_extension"] == "" || $resource_data["preview_extension"] == "")
        {
        return array();
        }

    
$extensions = array($resource_data["file_extension"], $resource_data["preview_extension"]);
    
$all_image_sizes = array();

    foreach(
$extensions as $extension)
        {
        
$available_sizes_by_extension get_image_sizes($reftrue$extensiontrue);

        foreach(
$available_sizes_by_extension as $size_data)
            {
            
$size_id trim($size_data["id"]) === "" "original" $size_data["id"];

            if(
array_key_exists($size_id$all_image_sizes))
                {
                continue;
                }

            
$key "{$size_id}_{$size_data["extension"]}";
            
$all_image_sizes[$key]["size_code"] = $size_id;
            
$all_image_sizes[$key]["extension"] = $size_data["extension"];
            
$all_image_sizes[$key]["path"] = $size_data["path"];
            
$all_image_sizes[$key]["url"] = $size_data["url"];

            
// Screen size can have multi page previews so if this is one of those cases, get rest of the pages before 
            // moving on to the next available size
            
if($size_id == "scr" && ($page_count get_page_count($resource_data)) && $page_count 1)
                {
                
// First page is always the normal scr size preview, so just tag it as such.
                
$all_image_sizes[$key]["multi_page"] = true;
                
$all_image_sizes[$key]["page"] = 1;

                for(
$page 2$page <= $page_count$page++)
                    {
                    
$path get_resource_path($reftrue"scr"false$extensiontrue$page);
                    if(!
file_exists($path))
                        {
                        continue;
                        }

                    
$url get_resource_path($reffalse"scr"false$extensiontrue$page);

                    
$key "{$size_id}_{$size_data["extension"]}_{$page}";
                    
$all_image_sizes[$key]["size_code"] = $size_id;
                    
$all_image_sizes[$key]["extension"] = $size_data["extension"];
                    
$all_image_sizes[$key]["multi_page"] = true;
                    
$all_image_sizes[$key]["page"] = $page;
                    
$all_image_sizes[$key]["path"] = $path;
                    
$all_image_sizes[$key]["url"] = $url;
                    }
                }
            }
        }

    return 
array_values($all_image_sizes);
    }

This article was last updated 24th November 2020 17:05 Europe/London time based on the source file dated 13th November 2020 16:50 Europe/London time.