<?PHP
function convert_PNG_to_JPG($source)
{
// $source = "1.jpg";
$convert = "D:\ImageMagick-6.6.3-Q16\convert.exe"; // define in constant.php
/* 一律 90 品質 */
if (filesize($source) > 524288)
{
$dest = str_replace('.png', '.jpg', $source);
echo "Q90 $dest \n";
exec($convert.' '.$source.' -strip -quality 90 '.$dest);
}
else
{
echo ".";
}
}
function convert_jpg_to_quality_90($source)
{
// $source = "1.jpg";
$convert = "D:\ImageMagick-6.6.3-Q16\convert.exe"; // define in constant.php
/* 一律 90 品質 */
if (filesize($source) > 524288)
{
echo "Q90 $source \n";
exec($convert.' '.$source.' -strip -quality 90 '.$source);
}
else
{
echo ".";
}
}
function shrink_to_goolge_800($source)
{
// $source = "1.jpg";
$mid = 800;
$convert = "D:\ImageMagick-6.6.3-Q16\convert.exe"; // define in constant.php
$size = getimagesize($source);
if ($size[0] > 800 || $size[1] > 800)
{
echo $source."\n";
usleep(10);
if ($size[0] > $size[1])
{
$toWWW = ( $size[0] >= $mid ? $mid : $size[0] );
//echo $convert.' '.$source.' -strip -resize '.$toWWW.'x '.$source;
exec($convert.' '.$source.' -resize '.$toWWW.'x '.$source);
}
else
{
$toHHH = ( $size[1] >= $mid ? $mid : $size[1] );
// echo $convert.' '.$source.' -strip -resize x'.$toHHH.' '.$source;
exec($convert.' '.$source.' -resize x'.$toHHH.' '.$source);
}
}
else
{
echo "-";
}
}
function prepare_readidr($pid)
{
/* 準備清單 */
$file_list = array();
if ($handle = opendir("."))
{
while (false !== ($filedir = readdir($handle)))
{
/* 確定目錄 */
if (is_dir($filedir))
{
/* 再從目錄讀出檔案 */
if ($handle2 = opendir($filedir))
while (false !== ($files = readdir($handle2)))
{
/* 不能是目錄 */
if (!is_dir($files))
{
$z = $filedir.'\\'.$files;
//if (filemtime($z) > (time() - 100))
// echo '.';
//else
shrink_to_goolge_800($z);
// convert_jpg_to_quality_90($z)
// convert_PNG_to_JPG($z)
}
}
}
}
}
}
/* main */
prepare_readidr();
?>