|
<?php |
|
|
|
error_reporting(0); |
|
|
|
$dh1 = opendir('.'); |
|
while (false !== ($directory = readdir($dh1))) { |
|
if(in_array($directory, ['..', '.', 'imgResize.php', '.DS_STORE'])) |
|
continue; |
|
if(is_dir($directory)){ |
|
$dh = opendir($directory); |
|
while (false !== ($filename = readdir($dh))) { |
|
if(!is_dir($filename)){ |
|
$filename = $directory.DIRECTORY_SEPARATOR.$filename; |
|
$pathinfo = pathinfo($filename, PATHINFO_EXTENSION); |
|
if(in_array($pathinfo, ['jpg', 'jpeg', 'png'])){ |
|
$percent = '0.'.$argv[1]; |
|
list($width, $height) = getimagesize($filename); |
|
$new_width = $width * $percent; |
|
$new_height = $height * $percent; |
|
$image_p = imagecreatetruecolor($new_width, $new_height); |
|
if($pathinfo == 'jpeg' || $pathinfo == 'jpg'){ |
|
$image = imagecreatefromjpeg($filename); |
|
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); |
|
imagejpeg($image_p, $filename, 100); |
|
}elseif($pathinfo == 'png'){ |
|
$image = imagecreatefrompng($filename); |
|
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); |
|
imagepng($image_p, $filename); |
|
} |
|
} |
|
} |
|
} |
|
}else{ |
|
$filename = $directory; |
|
$pathinfo = pathinfo($filename, PATHINFO_EXTENSION); |
|
$percent = '0.'.$argv[1]; |
|
if(in_array($pathinfo, ['jpg', 'jpeg', 'png'])){ |
|
list($width, $height) = getimagesize($filename); |
|
$new_width = $width * $percent; |
|
$new_height = $height * $percent; |
|
$image_p = imagecreatetruecolor($new_width, $new_height); |
|
if($pathinfo == 'jpeg' || $pathinfo == 'jpg'){ |
|
$image = imagecreatefromjpeg($filename); |
|
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); |
|
imagejpeg($image_p, $filename, 100); |
|
}elseif($pathinfo == 'png'){ |
|
$image = imagecreatefrompng($filename); |
|
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); |
|
imagepng($image_p, $filename); |
|
} |
|
} |
|
} |
|
} |
|
?> |