Skip to content

Instantly share code, notes, and snippets.

@francisrath
Last active June 5, 2018 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save francisrath/d76224f0821b570ac0458896f36589ed to your computer and use it in GitHub Desktop.
Save francisrath/d76224f0821b570ac0458896f36589ed to your computer and use it in GitHub Desktop.
<?php
require 'smartcrop.php'; // Download from https://raw.githubusercontent.com/xymak/smartcrop.php/master/smartcrop.php
use xymak\image;
$input_folder = "/vagrant/uploads/user_image/"; // Include trailing slash
$output_folder = "/vagrant/resized_images/"; // Must NOT be the same as input folder. Include tailing slash
$imageFiles = glob("${input_folder}*.{jpg,png}", GLOB_BRACE);
foreach ($imageFiles as $file) {
echo "Processing $file...";
$smartcrop = new xymak\image\smartcrop($file, [
'width' => 640,
'height' => 640
]);
$res = $smartcrop->analyse();
$smartcrop->crop($res['topCrop']['x'], $res['topCrop']['y'], $res['topCrop']['width'], $res['topCrop']['height']);
$path = pathinfo($file);
$smartcrop->output($output_folder . $path['filename'] . '.jpg');
echo " OK\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment