-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize PNG files #13509
Optimize PNG files #13509
Conversation
This reverts commit d7d9000.
what's the different between optimized PNG and lossless compressed PNG? |
the resulting image is identical, but the files are smaller. see https://linux.die.net/man/1/optipng |
@Bituvo It looks like you have merged master into this branch. This project prefers the rebase workflow, where if a branch needs to be updated, it should be rebased and force pushed instead of merging master. This keeps the history cleaner. See: .github/CONTRIBUTING.md |
FWIW it doesn't really matter what the contributor does to their branch since changes are squashed upon merging anyway. |
The texture changes increase the repository size because both the old and new versions are saved in the history, and the texture sizes are probably not optimal, so a future recompression may further decrease texture sizes and increase the repository size. I suggest to keep only file changes where the size reduction is at least 70% and to recompress them more aggressively with oxipng and advpng. changed_files=$(git diff --name-only master...)
for f in $changed_files; do
size_old=$(git cat-file -s "master:$f")
size_new=$(git cat-file -s "@:$f")
if ((size_old * 7 > size_new * 10)); then
echo "$f"
fi
done # Requires imagemagick, oxipng and advpng
png_shrink() {
file=$1
size_initial=$(stat --printf='%s' "$file")
size_prev=$size_initial
while true; do
if [[ $(convert "$file" -format "%[opaque]" info:) == "False" ]]; then
# There is an alpha channel. Keep colour in transparent pixels.
oxipng --nc --opt max --zopfli "$file"
oxipng --nc --opt max "$file"
else
advpng --shrink-insane --recompress "$file"
oxipng --opt max --zopfli "$file"
oxipng --opt max "$file"
fi
size=$(stat --printf='%s' "$file")
if [[ "$size" -eq "$size_prev" ]]; then
break
fi
size_prev=$size
done
if [[ "$size_initial" -eq "$size_prev" ]]; then
echo "No size reduction"
else
size_initial_ie=$(numfmt --to=iec-i "$size_initial")B
size_final_ie=$(numfmt --to=iec-i "$size_prev")B
echo "Size reduced from $size_initial_ie to $size_final_ie"
fi
}
# Shrink only images which are small enough
pngs_shrink() {
threshold=$1
shift
for f in $@; do
num_pixels=$(identify -format '%[fx:w*h]' "$f")
if ((num_pixels < threshold)); then
echo "$f"
png_shrink "$f"
fi
done
}
changed_files=$(git diff --name-only master...)
pngs_shrink 1000 $changed_files |
Even if the git repository size is larger, the release sizes will be smaller. From an end-user point of view, I think it is good to have the textures compressed. |
Since you wrote "minetest_game optimizer", I assume you used If I do the same, I get slightly different results. Here's a commit comparing my results with yours: d714c09
Also, this PR probably needs an update because new PNG files have been added to the repo in the meantime. |
Will do. |
hate to bring this up, I wrote the optimize script a while back - just wanted to clarify a few things:
|
Yet another trivial PR. I ran all of the PNG files through the minetest_game optimizer. I'm not sure how many kilobytes I saved, but I know it's more than one.