These scripts and commands are used to convert various image files to TGA format, with options to handle different file types (PCX, JPG, JPEG) and color spaces. They use tools like wal2tga
, convert
, and find
to automate the conversion process in Windows and Bash environments.
for /r %%v in (*.wal) do "Z:\planet_quake_data\tools\Wal2TGA\wal2tga copy.exe" "%%v" "%%~dpv%%~nv.tga"
# TODO: bash uses glob, windows can use "or" keyword
#windows
for /r %%v in (*.pcx or *.jpg or *.jpeg) do convert -colorspace RGB "%%v" "%%~dpv%%~nv.tga" ; done
#bash
for i in $(find . -iname '*.pcx' -o -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.tga'); \
do if [ ! -f "${i%.*}.tga" ]; \
then convert -colorspace RGB "$i" "${i%.*}.tga"; \
fi; \
done;
convert -colorspace RGB pak0.pk3dir/models/deadbods/dude/dead1.pcx pak0.pk3dir/models/deadbods/dude/dead1.tga
bash
#!/bin/bash
# Define the base directory for the quake data
DATA_DIR="Z:\planet_quake_data"
# Define the tool executable and output directory
TOOL_EXEC="wal2tga copy.exe"
OUTPUT_DIR="$DATA_DIR/tools/Wal2TGA"
# Convert PCX and JPEG images to TGA
for image in $(find "$DATA_DIR" -iname '*.pcx' -o -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.tga'); do
# Get the input file name and location without the extension
IN_FILE="${image##*/}"
OUT_FILE="${IN_FILE%.*}.tga"
# Check if the output file already exists
if [! -f "$OUTPUT_DIR/$OUT_FILE" ]; then
# Convert the image to TGA using Imagemagick
convert -colorspace RGB "$image" "$OUTPUT_DIR/$OUT_FILE"
fi
done
Code Breakdown
for /r %%v in (*.wal) do "Z:\planet_quake_data\tools\Wal2TGA\wal2tga copy.exe" "%%v" "%%~dpv%%~nv.tga"
.wal
extension in the current directory and its subdirectories (/r
option).wal2tga copy.exe
executable from the specified path, passing the file path (%%v
) and a new TGA file path generated by combining the original file's directory path (%%~dpv
) and name (%%~nv
) with a .tga
extension.for /r %%v in (*.pcx or *.jpg or *.jpeg) do convert -colorspace RGB "%%v" "%%~dpv%%~nv.tga" ; done
.pcx
, .jpg
, and .jpeg
extensions.convert
command from ImageMagick, converting the file to RGB color space and saving it as a new TGA file in the same directory.for i in $(find. -iname '*.pcx' -o -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.tga'); \
do if [! -f "${i%.*}.tga" ]; \
then convert -colorspace RGB "$i" "${i%.*}.tga"; \
fi; \
done;
find
to search for files with the .pcx
, .jpg
, .jpeg
, and .tga
extensions in the current directory and its subdirectories (.
).convert
command from ImageMagick, converting the file to RGB color space and saving it as a new TGA file in the same directory.convert -colorspace RGB pak0.pk3dir/models/deadbods/dude/dead1.pcx pak0.pk3dir/models/deadbods/dude/dead1.tga
convert
command from ImageMagick.