Skip to content
/ repage Public

Repage removes the background based on a threshold, then positions the remaining image centrally in the specified output size.

Notifications You must be signed in to change notification settings

andyg2/repage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Image repager - attempts to remove background, crops and positions centrally

From this

To this

DIRECTORIES

$p['source'] = './source/'; // path of source images with trailing slash
$p['dest'] = './dest/'; // path of destination images with trailing slash

FILE NAMING

Adds dimentions to file [basename]-1200x900.jpg and, if destination exists increments filename is_integer [basename]-1200x900-2.jpg

$p['autoname'] = false;

DESTINATION_DIMENSIONS

defaults to 800 x 600 if omitted

$p['destination_width'] = 1200;
$p['destination_height'] = 900;

BACKGROUND_COLOR - defaults to white if omitted

Specify rgb values

$p['background_color']['r'] = 127;
$p['background_color']['g'] = 127;
$p['background_color']['b'] = 127;

Or: Use hex value

$p['background_color'] = '#CCCCCC';

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.
$p['source'] = './source/';
$p['dest'] = './dest/';
$p['autoname'] = false;
$p['destination_width'] = 1200;
$p['destination_height'] = 900;
$p['background_color'] = 10;
$p['image_padding'] = 20;
$p['cropping_threshold'] = 'auto';

Single image

args for repage_image($p)

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.
$p['input_image'] = './source/jack-daniels.jpeg';
$p['output_image'] = './dest/jack-daniels.jpeg';
$p['autoname'] = true;
$p['destination_width'] = 400;
$p['destination_height'] = 300;
$p['background_color']['r'] = 255;
$p['background_color']['g'] = 255;
$p['background_color']['b'] = 255;
$p['image_padding'] = 100;
$p['cropping_threshold'] = 'auto';

Source

Result

About

Repage removes the background based on a threshold, then positions the remaining image centrally in the specified output size.

Topics

Resources

Stars

Watchers

Forks

Languages