Php implements a script to batch compress image files. Today, I want to upload a large number of images to the Forum. because the images are made by SLR cameras and the size is large, I wrote a script to compress images in batches. Phpif ($ handleopendir (. old) {while (fal today, I want to upload a large number of images to the Forum. because the images are made by SLR cameras and the size is large, I wrote a script to compress images in batches.
<?phpif ($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();}?>
Bytes. Phpif ($ handle = opendir ('./old') {while (fal...