欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php實現(xiàn)批量壓縮圖片文件大小的腳本

 更新時間:2014年07月04日 10:53:56   作者:王玉鵬  
這篇文章主要介紹了php實現(xiàn)把某個目錄下的圖片進行批量壓縮文件大小的腳本,單反拍的圖片,體積太大,所以要壓縮,需要的朋友可以參考下

今天,想上傳大量圖片到論壇,由于圖片是單反拍的,體積較大,就寫了一個腳本,批量壓縮圖片。

<?php

if ($handle = opendir('./old')) {

    while (false !== ($file = readdir($handle))) {
        if ($file == '.' || $file == '..') {
            continue;
        }
        write('d:/wamp/www/test/old/'.$file, 'd:/wamp/www/test/new/'.$file);
    }

    closedir($handle);
}


function write($old, $new) {
    $maxsize=1000;
    $image = new Imagick($old);
    if($image->getImageHeight() <= $image->getImageWidth())
    {
        $image->resizeImage($maxsize,0,Imagick::FILTER_LANCZOS,1);
    }
    else
    {
        $image->resizeImage(0,$maxsize,Imagick::FILTER_LANCZOS,1);
    }
    $image->setImageCompression(Imagick::COMPRESSION_JPEG);
    $image->setImageCompressionQuality(90);
    $image->stripImage();
    $image->writeImage($new);
    $image->destroy();
}
?>

相關文章

最新評論