exiftool_resolution_calc()

Description

Extract and store dimensions, resolution, and unit (if available) from exif data
Exiftool output format (tab delimited): widthxheight resolution unit (e.g., 1440x1080 300 inches)

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 363 to 405

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 ";
    
$command .= escapeshellarg($file_path);
    
$exif_output explode("\t"run_command($command));

    if (
count($exif_output) >= && $exif_output[0] != '') {
        if (
$remove_original) {
            
ps_query("DELETE FROM resource_dimensions WHERE resource= ?", ['i'$ref]);
        }
        
$wh explode("x"$exif_output[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
            
];

            for (
$n 1$n count($exif_output); $n++) {
                
# Resolution may be omitted if not set; check values by type
                
if (is_int_loose($exif_output[$n])) {
                    
$sql_insert .= ",resolution";
                    
$sql_params[] = 'i';
                } else {
                    
$sql_insert .= ",unit";
                    
$sql_params[] = 's';
                }
                
$sql_params[] = $exif_output[$n];
            }

            
$sql_insert .= ")";
            
$sql_values "values (" ps_param_insert((count($sql_params) / 2)) . ")";
            
$sql $sql_insert $sql_values;
            
ps_query($sql$sql_params);
        }
    }
}

This article was last updated 8th June 2025 14:35 Europe/London time based on the source file dated 4th June 2025 20:05 Europe/London time.