Aug
07
2013
php批量处理图片大小
<?php require_once (dirname ( __FILE__ ) . "/include/common.inc.php"); require_once ("/admin/inc/inc_archives_functions.php"); function myscandir($path) { $mydir = dir ( $path ); while ( $file = $mydir->read () ) { $p = $path . '/' . $file; if (($file != ".") and ($file != "..")) { $file_arr [] = $p; } if ((is_dir ( $p )) and ($file != ".") and ($file != "..")) { myscandir ( $p ); } } return $file_arr; } $file_arr = myscandir ( 'F:/3g_88353588_net/uploads/allimg/130805' ); foreach ( $file_arr as $file ) { list ( $width, $height ) = getimagesize ( $file ); //echo $file . '->' . $width . '*' . $height . '<hr/>'; $max_width = 300; if ($width > $max_width) { $ratio = round ( $width / $max_width, 2 ); $ToHeight = round ( $height / $ratio, 2 ); ImageResize ( $file, $max_width, $ToHeight ); list ( $width, $height ) = getimagesize ( $file ); echo $file . '->' . $width . '*' . $height . '<hr/>'; } } /* * list ( $width, $height ) = getimagesize ( "87973926602.jpg" ); $max_width = * 300; $ratio = round ( $width / $max_width, 2 ); $ToHeight = round ( $height / * $ratio, 2 ); ImageResize ( $value, $max_width, $ToHeight ); */ ?>
最活跃的读者