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 321 to 356

Definition

 
function exiftool_resolution_calc($file_path$ref$remove_original false)
{
    
$exiftool_fullpath get_utility_path("exiftool");
    
$command $exiftool_fullpath " -s -s -s %s ";
    
$command .= escapeshellarg($file_path);
    
$exif_output run_command(sprintf($command"-composite:imagesize"));

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

            
$exif_resolution run_command(sprintf($command'-xresolution'));
            
$exif_unit run_command(sprintf($command'-resolutionunit'));
            
$sql_insert .= ',resolution,unit';
            
$sql_params array_merge($sql_params, ['s'$exif_resolution's' $exif_unit]);

            
$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 30th June 2025 17:35 Europe/London time based on the source file dated 27th June 2025 16:50 Europe/London time.