Or: Detect background colors - average color of 10 pixels in from each corder
$p['background_color'] = 10; // (auto)
IMAGE_PADDING
Add 20 pixels additional border to crop
$p['image_padding'] = 20;
CROPPING_THRESHOLD
Automatic
$p['cropping_threshold'] = 'auto';
Or Specify a threshold
$p['cropping_threshold'] = 50;
Examples
Batch images
args for batch_repage($p)
Process all images in ./source/.{png,jpeg,jpg,gif}, save as original filenames in ./dest/ as a 1200 x 900 image, get background color from 10px in from the corners, add additional 20px padding to cropped image.
Process './source/jack-daniels.jpeg', save as './dest/jack-daniels-400x300.jpeg' (autoname) as a 400 x 300 image, white background color for fropping and fill, add 100px padding around cropped image.