ImageProc/bin/process-images.php

52 lines
1.6 KiB
PHP
Raw Normal View History

2020-01-10 12:53:32 -07:00
<?php
$time_start = microtime(true);
include_once("functions.inc.php");
include_once("config.inc.php");
//$img = new Imagick('/path/to/file');
//autorotate($img);
//$img->stripImage(); // if you want to get rid of all EXIF data
//$img->writeImage();
2020-04-01 12:48:09 -06:00
$progVersion="v2.0.1-PHP";
2020-01-10 12:53:32 -07:00
$phpVersion=phpversion();
2020-04-01 12:48:09 -06:00
$imagickVersion=imagick::getVersion();
2020-01-10 12:53:32 -07:00
$rawDir="raw/";
$outDir="resized/";
2020-04-01 12:48:09 -06:00
echo "ImageProc ".$progVersion."\nPHP ".$phpVersion."\n".$imagickVersion['versionString']."\n\n\n";
2020-01-10 12:53:32 -07:00
$dateInput=readline("Current Date (press enter for ".date('mdy')."): ");
$startNumInput=readline("Starting Number: ");
if (empty($dateInput)) {
$dateInput=date('mdy');
}
if (empty($startNumInput)) {
$startNumInput="1";
}
echo "\n";
foreach(glob($rawDir.'*.{jpg,JPG,jpeg,JPEG}',GLOB_BRACE) as $filename){
$outputName=basename($filename);
$outImgFile=sprintf("%s/%s-%04d.jpg",$outDir, $dateInput, $startNumInput);
echo "#";
$img=new Imagick($filename);
2020-04-01 12:48:09 -06:00
$iccProfiles = $img->getImageProfiles("icc", true);
2020-01-10 12:53:32 -07:00
autorotate($img);
$img->stripImage();
2020-04-01 12:48:09 -06:00
if(!empty($profiles)) {
$img->profileImage("icc", $iccProfiles['icc']);
}
2020-01-10 12:53:32 -07:00
// This is kinda slow sometimes, so we'll try using scaleImage instead
//$img->resizeImage($imgWidth, $imgHeight, imagick::FILTER_CATROM, 1);
2020-04-01 12:48:09 -06:00
$img->setImageDepth(8);
2020-01-10 12:53:32 -07:00
$img->scaleImage($imgWidth, $imgHeight, FALSE);
2020-04-01 12:48:09 -06:00
$img->setImageCompression(Imagick::COMPRESSION_JPEG);
2020-01-10 12:53:32 -07:00
$img->setImageCompressionQuality($imgQuality);
$img->writeImage($outImgFile);
$img->destroy();
$startNumInput++;
}
echo "\n\nTotal Runtime: ".ceil((microtime(true) - $time_start))." seconds";
echo "\n";
readline("");
?>