Я прочитал man pngcrush
, и кажется, что нет способа раздавить файл PNG и сохранить его поверх оригинала. Я хочу сжать несколько папок PNG, поэтому было бы полезно сделать все это одной командой!
В настоящее время я делаю pngcrush -q -d tmp *.png
, а затем вручную обрезаю файлы из каталога tmp
в оригинальная папка. Я думаю, что использование mv
может быть лучшим способом? Есть идеи получше?
Все в одной строке:
for file in *.png; do pngcrush "$file" "${file%.png}-crushed.png" && mv ${file%.png}-crushed.png" "$file"; done
должны это сделать.
(Хотя до сих пор в моих собственных тестах менее половины pngs, на которых я тестировал pngcrush
, впоследствии были меньше, поэтому цвет меня не впечатлил.)
Начиная с версии 1.7.22, pngcrush
имеет опцию перезаписи.
Попробуйте
pngcrush -ow file.png
См. Список изменений для получения дополнительной информации:
Version 1.7.22 (built with libpng-1.5.6 and zlib-1.2.5)
Added "-ow" (overwrite) option. The input file is overwritten and the
output file is just used temporarily and removed after it is copied
over the input file.. If you do not specify an output file, "pngout.png"
is used as the temporary file. Caution: the temporary file must be on
the same filesystem as the input file. Contributed by a group of students
of the University of Paris who were taking the "Understanding of Programs"
course and wished to gain familiarity with an open-source program.