Skip to content

Instantly share code, notes, and snippets.

@bikubi
Last active October 10, 2017 13:49
Show Gist options
  • Save bikubi/cdb696cbd7bc2d9ef9673ddcc917e21c to your computer and use it in GitHub Desktop.
Save bikubi/cdb696cbd7bc2d9ef9673ddcc917e21c to your computer and use it in GitHub Desktop.
baseq3 cagifier
#!/bin/bash
# Replaces all textures in Q3A with Nick Cage, as pitched by Nerdcore
# http://www.nerdcore.de/2017/10/05/that-time-some-gamedev-replaced-every-texture-with-nicolas-cage/
# commenting on @AmazingThew
# https://twitter.com/AmazingThew/status/915787837349531648
# Example output:
# https://vimeo.com/237570637
#
# USAGE
# ./cagify.sh PATH-TO-BASEQ3 PATH-TO-NICK-IMAGE
#
# You'll need imagemagick, zip & unzip. Tested with Arch Linux's find, bash, etc.
BASEQ3="$1"
BASENICK="$2"
TMP="/tmp"
ZIPTMP="/tmp/nickzip"
for pk3path in $BASEQ3/*.pk3; do
pk3=$(basename "$pk3path")
# unfortunately archivemount doesn't work - it turns the ZIPs into TARs...
#mntdir="$TMP/mnt_$pk3"
#mkdir -v "$mntdir"
#archivemount "$pk3path" "$mntdir"
echo "$pk3path..."
unzip "$pk3path" -d "$ZIPTMP"
for img in $(find "$ZIPTMP" -regextype grep -iregex '.*\(jpg\|tga\)$'); do
size="$(identify -format "%[fx:w]x%[fx:h]" "$img")"
ext="${img##*.}"
nick="$TMP/nick_$size.$ext"
echo "$img: $size $ext"
if [ ! -f "$nick" ] ; then
convert -verbose "$BASENICK" -resize $size! "$nick"
fi
cp -v "$nick" "$img"
done
cd "$ZIPTMP"
zip -ur "$pk3path" *
cd -
rm -rf "$ZIPTMP" # careful
#fusermount -u "$mntdir"
#rmdir -v "$mntdir"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment