linux下修改并当前目录下图像文件并删除

Linux下;

需要安装 Image Magick。

仅供参考,注意安全。

使用时注意修改。

#!/usr/bin/perl
# change image size
use strict;
use warnings;

# get files to be modified
print "Image Format(jpg or JPG or else): ";
chomp(my $format = <STDIN>);
my @files = glob "*.$format";

my $filename;
for (@files) {
	# file name
	$filename = /(\d+\.jpg)/i ? $1 : "1_$_";

	# change size
	system "convert -sample 25%x25% '$_' $filename";

	print "converting $_ ...\n";
}
print "Convert finished!\n\nRemove files:\n@files...??????????????????\n\nYes or No?: ";
chomp(my $choice = <STDIN>);

if ($choice =~ /^y/i) {
	foreach (@files) {
		system "rm '$_' -v";
	}
} else {
	print "OK, I won't delete them. Bye!\n";
	exit;
}

print "Done!\n";

你可能感兴趣的:(linux,批量处理图片)