Collections functions
General functions
Render functions
Theme permission functions
Resource functions

exiftool_resolution_calc()

Description

Set resource dimensions using data from exiftool.

Parameters

ColumnTypeDefaultDescription
$file_path string Path to the original file.
$ref int Reference of the resource.
$remove_original boolean false Option to remove the original record. Used by update_resource_dimensions.php

Return

void

Location

include/metadata_functions.php lines 380 to 428

Definition

 
function exiftool_resolution_calc($file_path$ref$remove_original false)
    {
    
$exiftool_fullpath get_utility_path("exiftool");
    
$command $exiftool_fullpath " -s -s -s -t -composite:imagesize -xresolution -resolutionunit " escapeshellarg($file_path);
    
$dimensions_resolution_unit=explode("\t",run_command($command));
        
    
# if dimensions resolution and unit could be extracted, add them to the database.
    # they can be used in view.php to give more accurate data.
    
if (count($dimensions_resolution_unit)>=&& $dimensions_resolution_unit[0]!='')
        {
        if (
$remove_original)
            {
            
$delete=ps_query("delete from resource_dimensions where resource= ?", ['i'$ref]);
            }
        
$wh=explode("x",$dimensions_resolution_unit[0]);
        if(
count($wh)>1)
            {
            
$width=$wh[0];
            
$height=$wh[1];
            
$filesize=filesize_unlimited($file_path);
            
$sql_insert ="insert into resource_dimensions (resource,width,height,file_size";
            
$sql_params = [
                
's'$ref,
                
'i'$width,
                
'i'$height,
                
's'$filesize
            
];
            
            if(
count($dimensions_resolution_unit)>=2)
                {
                
$resolution=$dimensions_resolution_unit[1];
                
$sql_insert.=",resolution";
                
$sql_params[] = 's'$sql_params[] = $resolution;
                
                if(
count($dimensions_resolution_unit)>=3)
                    {
                    
$unit=$dimensions_resolution_unit[2];
                    
$sql_insert.=",unit";
                    
$sql_params[] = 's'$sql_params[] = $unit;
                    }
                }
                
            
$sql_insert.=")";
            
$sql_values "values ("ps_param_insert((count($sql_params)/2)) .")";
            
$sql=$sql_insert.$sql_values;
            
$wait=ps_query($sql$sql_params);
            }
        }
    }

This article was last updated 3rd October 2022 11:35 Europe/London time based on the source file dated 5th July 2022 12:30 Europe/London time.