Skip to content

Instantly share code, notes, and snippets.

@floxay
Created July 31, 2025 20:22
Show Gist options
  • Select an option

  • Save floxay/4f5bbaa43f795c50fb84dd5d210646c7 to your computer and use it in GitHub Desktop.

Select an option

Save floxay/4f5bbaa43f795c50fb84dd5d210646c7 to your computer and use it in GitHub Desktop.
VALORANT Simple Spray masker
# /// script
# requires-python = ">=3.9"
# dependencies = [
# "opencv-python-headless",
# ]
# ///
from pathlib import Path
import cv2
SCRIPT_DIR = Path(__file__).parent
RAW_SPRAY_DIR = SCRIPT_DIR / "raw"
OUTPUT_SPRAY_DIR = SCRIPT_DIR / "output"
SUPPORTED_EXTENSION = "png"
def create_transparent_spray(diffuse_path: Path) -> None:
name = diffuse_path.stem.removesuffix("_DF")
print(f"Converting {name}...")
aem_path = diffuse_path.parent / f"{name}_AEM.{SUPPORTED_EXTENSION}"
if not aem_path.exists() or not aem_path.is_file():
raise RuntimeError(f"Issue locating AEM texture at: {aem_path.resolve()}")
df_img = cv2.imread(str(diffuse_path.resolve()))
aem_img = cv2.imread(str(aem_path.resolve()))
if df_img is None:
raise RuntimeError(f"Error reading DF texture at: {diffuse_path.resolve()}")
if aem_img is None:
raise RuntimeError(f"Error reading AEM texture at: {diffuse_path.resolve()}")
bgra = cv2.cvtColor(df_img, cv2.COLOR_BGR2BGRA)
bgra[:, :, 3] = aem_img[:, :, 0]
out_path = OUTPUT_SPRAY_DIR / f"{name}_Transparent.{SUPPORTED_EXTENSION}"
cv2.imwrite(str(out_path.resolve()), bgra, [cv2.IMWRITE_PNG_COMPRESSION, 4])
print(f"Converted {name}")
if __name__ == "__main__":
if not RAW_SPRAY_DIR.exists():
raise RuntimeError(
f"Raw spray directory was not found at {RAW_SPRAY_DIR.resolve()}"
)
OUTPUT_SPRAY_DIR.mkdir(exist_ok=True)
for path in RAW_SPRAY_DIR.iterdir():
if not path.is_file():
continue
if not path.name.endswith("_DF.png"):
continue
try:
create_transparent_spray(path)
except Exception as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment