31 lines
915 B
PHP
31 lines
915 B
PHP
|
<?php
|
|||
|
/*
|
|||
|
Уменьшает jpg за счет снижения качества, запуск "php compress_jpg.php" в нужной папке с картинками
|
|||
|
*/
|
|||
|
$zip=70;
|
|||
|
function list_file ( $dir ) {
|
|||
|
if ( $dir [ strlen( $dir ) - 1 ] != '/' ) $dir .= '/';
|
|||
|
$nDir = opendir( $dir );
|
|||
|
while ( false !== ( $file = readdir( $nDir ) ) ){
|
|||
|
if ( $file != "." AND $file != ".." ){
|
|||
|
if ( !is_dir( $dir . $file ) ){
|
|||
|
$files [] = $file;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
closedir( $nDir );
|
|||
|
return $files;
|
|||
|
}
|
|||
|
function get_file_extension($filename) {
|
|||
|
return @end(@explode(".", $filename));
|
|||
|
}
|
|||
|
mkdir('./bak', 0700);
|
|||
|
$lf=(list_file('.'));
|
|||
|
$count=count($lf);
|
|||
|
for ($i = 0; $i < $count; $i++) {
|
|||
|
if (get_file_extension($lf[$i])=='jpg'){
|
|||
|
copy ($lf[$i], './bak/' . $lf[$i]);
|
|||
|
exec('convert ' . $lf[$i] . ' -strip -quality ' . $zip . ' ' . $lf[$i]);
|
|||
|
}
|
|||
|
}
|
|||
|
?>
|