Collections functions
General functions
Node functions
Render functions
Theme permission functions
User 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 392 to 440

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)
            {
            
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;
            
ps_query($sql$sql_params);
            }
        }
    }

This article was last updated 19th March 2024 06:35 Europe/London time based on the source file dated 6th March 2024 14:45 Europe/London time.