我有一个 jpg 图片文件夹,编号为“01.jpg”到“24.jpg”。
它们有各种不同的尺寸。我的电视仅按大小对 U 盘文件进行排序... 我需要一种有效的方法来压缩所有图像,因此按大小排序与按名称排序相匹配。
我试着手动做,但很快发现这是个坏主意。
首先:这是一个 X-Y 问题。潜在的问题是你的电视不会让你按名字排序。
也就是说,这是一个有趣的问题。然而,适当压缩图像以确保顺序可能是 hard 并且可能会导致质量显着下降。如果您不想牺牲质量,则必须 bloat 图像。这也简单得多。这是一个 Bash 脚本,它使 JPEG 图像膨胀以强制按其命名强加的顺序:
#!/bin/bash
maxsize=0
for file in *.jpg
do
size=$(stat --format %s $file)
if [[ $size -gt $maxsize ]]
then
maxsize=$size
echo "$file has correct size of $size bytes already"
else
maxsize=$((maxsize+128))
tobloat=$((maxsize-size))
# Dirty, dirty hack: Embed the bloat string as a comment
# (which can get arbitrarily large);
# use a temporary file to not run into the shell command length limit
tmpfile=$(mktemp /tmp/jpeg-bloating.XXXXXX)
while [ $tobloat -ne 0 ]
do
tobloat=$(($tobloat-1))
echo -n 'a' >> "$tmpfile"
done
exiftool $file -overwrite_original '-Comment<='"$tmpfile"
rm "$tmpfile"
echo "$file bloated to $(stat --format %s $file) bytes"
fi
done
使用
exiftool
适当添加多个a
作为