Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

prepareFaceImage()

Description

Crops out a selected area of an image and makes it ready to be used by FaceRecognizer.

Note: The selected area should follow the normalized coordinate system.

Parameters

ColumnTypeDefaultDescription
$image_path string Path of the source image
$prepared_image_path string Path of the prepared image
$x float X position
$y float Y position
$width float Width
$height float Height
$overwrite_existing boolean false Set to TRUE to overwrite existing prepared image (if any exists)

Return

boolean

Location

include/facial_recognition_functions.php lines 86 to 135

Definition

 
function prepareFaceImage($image_path$prepared_image_path$x$y$width$height$overwrite_existing false)
    {
    if(!
file_exists($image_path))
        {
        
debug("FACIAL_RECOGNITION: Could not find image at '{$image_path}'");
        return 
false;
        }

    
// Use existing prepared image if one is found
    
if(!$overwrite_existing && file_exists($prepared_image_path))
        {
        return 
true;
        }

    
// X, Y, width and height MUST be numeric
    
if(!is_numeric($x) || !is_numeric($y) || !is_numeric($width) || !is_numeric($height))
        {
        return 
false;
        }

    
$convert_fullpath get_utility_path('im-convert');
    if(
false === $convert_fullpath)
        {
        
debug('FACIAL_RECOGNITION: Could not find ImageMagick "convert" utility!');
        return 
false;
        }

    list(
$image_width$image_height) = getimagesize($image_path);

    
$image_path_escaped          escapeshellarg($image_path);
    
$prepared_image_path_escaped escapeshellarg($prepared_image_path);

    
$x      escapeshellarg(round($x $image_width0));
    
$y      escapeshellarg(round($y $image_height0));
    
$width  escapeshellarg(round($width $image_width0));
    
$height escapeshellarg(round($height $image_height0));

    
$cmd  $convert_fullpath;
    
$cmd .= {$image_path_escaped} -colorspace gray -depth 8";
    
$cmd .= " -crop {$width}x{$height}+{$x}+{$y}";
    
$cmd .= " -resize 90x90\>";
    
$cmd .= " +repage {$prepared_image_path_escaped}";

    if(
'' !== run_command($cmd))
        {
        return 
false;
        }

    return 
true;
    }

This article was last updated 17th November 2024 15:35 Europe/London time based on the source file dated 19th September 2024 17:30 Europe/London time.