Luxand FaceCrop SDK – Using with PHP
The FaceCrop library offers an extension for PHP called luxand_facecrop. Using this extension, one can call the FaceCrop functions from applications written in PHP. The method to connect this extension to PHP depends on the type of operating system in use.
There are two ways to install FaceCrop PHP extension on UNIX-compatible OS (such as Linux, Mac OS X).
A. Installing as pluggable module
1. Copy libfacecrop.so (or libfacecrop.dylib) to /usr/lib and LuxandFaceCrop.h to /usr/include (or to /usr/local/lib and /usr/local/include)
2. Go to luxand_facecrop folder and type:
phpize && ./configure && make && make install
3. Make sure you have extension=luxand_facecrop.so in your php.ini
B. Compiling luxand_facecrop into PHP
1. Copy libfacecrop.so (or libfacecrop.dylib) to /usr/lib and LuxandFaceCrop.h to /usr/include (or to /usr/local/lib and /usr/local/include)
2. Copy files from luxand_facecrop to $PHP_SOURCE_DIR/ext/luxand_facecrop
3. In PHP source root directory, run commands:
rm configure && ./buildconf --force
4. Configure PHP with command:
./configure –with-luxand_facecrop
5. Run make && make install:
make && make install
Installing on Windows
To install FaceCrop PHP extension on Windows with PHP 5.3:
1. Install Microsoft Visual Studio 2008.
2. Install Windows SDK 6.1
3. Get a PHP 5.3 current snapshot or 5.3 stable release archive (but do not extract yet)
4. Create the folder "c:\php-sdk"
5. Unpack the binary-tools.zip archive into this directory. There should be one sub-directory called "bin" and one called "script". The binary-tools.zip archive can be downloaded from http://pecl2.php.net/downloads/php-windows-builds/php-libs/
6. Open the "windows sdk 6.1 cmd shell" (it is available from the Start menu group) and execute the following commands inside the shell:
setenv /x86 /xp /release
cd c:\php-sdk\
bin\phpsdk_setvars.bat
bin\phpsdk_buildtree.bat php53dev
7. Extract the PHP snapshot from 3. to:
c:\php-sdk\php53dev\vc9\x86
so the following directory is created:
c:\php-sdk\php53dev\vc9\x86\php-5.3XXXXXXX
8. Copy facecrop.lib to:
c:\php-sdk\php53dev\vc9\x86\deps\lib\
9. Copy luxand_facecrop directory to:
c:\php-sdk\php53dev\vc9\x86\php-5.3XXXXXXX\ext\
10. If you want to build PHP with Apache support, copy all from lib\ and include\ directories from the Apache directory to:
c:\php-sdk\php53dev\vc9\x86\deps\lib\
and:
c:\php-sdk\php53dev\vc9\x86\deps\include\
11. Run in the windows-sdk-shell:
cd C:\php-sdk\php53dev\vc9\x86\php-5.3XXXXXXX
buildconf
configure --help
12. Run configure with options you wish to include --with-luxand_facecrop, e.g.:
configure --enable-apache2-2handler --enable-isapi --enable-cli --with-luxand_facecrop
nmake
13. If you need the resulting PHP to be zipped, run after this also:
nmake snap
14. The compiled PHP supporting FaceCrop is now under:
c:\php-sdk\php53dev\vc9\x86\php-5.3XXXXXXX\Release_TS
Copy it with facecrop.dll to the desired location (e.g. to c:\Windows\System32\)
Functions Available in PHP
In the PHP extension, there are the following functions available:
fcActivate,
fcGetHardwareID,
fcGetLicenseInfo,
fcFaceCrop,
fcGetFacePosition,
fcSetFaceScale,
fcSetFaceShift,
fcSetDetectionThreshold,
fcSetDetectionPerformance,
fcSetJpegQuality,
fcCreateContextID,
fcFreeContextID.
As you work with the extension, it is necessary to use the mechanism of contexts (see the Thread Safety and Contexts chapter). Therefore all specified functions, except:
fcActivate,
fcGetHardwareID,
fcGetLicenseInfo,
accept context ID as the final parameter.
You should work with the PHP extension as follows:
- Activate the library using the fcActivate call
- Create the context using the fcCreateContextID call
- Call extension functions by transferring context ID as the final parameter of each used function.
- When the program is over, free the context using fcFreeContextID.
The fcFinalize call in PHP applications is not required.
Example:
<?php
fcActivate("YOUR_LICENSE_KEY");
$c_id = fcCreateContextID();
fcFaceCrop($infile, $outfile, 128, 196, $c_id);
fcFreeContextID($c_id);
?>