-
-
Save francisrath/d76224f0821b570ac0458896f36589ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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