人氣點閱:6221 |
發表人 |
PHP + ImageMagick Codes: PNG2JPG, JPG Quality, Shrink JPG 2014-06-29 16:15 |
/ / /
|
|
PHP + ImageMagick Codes: PNG2JPG, JPG Quality, Shrink JPG Quality
PHP Read All files in this directory and the proceed the following Image processing
1. convert_PNG_to_JPG($source): Convert PNG image files to JPG image files within this directory
2. convert_jpg_to_quality_90($source): Convert JPG quality to 90 within same folder
3. shrink_to_goolge_800($source): Shrink all images files in this folder to max 800 width or 800 height
代碼:
<?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();
?>
________________
美術插畫設計案子報價系統 v0.1 Beta
爪哇禾雀
|
|
Type
繪圖畫廊 設計藝廊 攝影相簿 留言板 最愛收藏 分類標籤
暱稱: Type 註冊: 2002-11-30 發表: 11172 來自: vovo2000.com
V幣: 901758
|
|
|
|
|