virt2/api/php/compress_jpg.php

31 lines
915 B
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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]);
}
}
?>