GithubHelp home page GithubHelp logo

andyg2 / repage Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 852 KB

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

PHP 100.00%
background-removal centering crop-image gd image-processing php7 resize-images

repage's Introduction

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

repage's People

Contributors

andyg2 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.