Open pairofdocs opened 3 years ago
a working python script that saves images to .\processed_items_D2R\
import glob
import subprocess
import time
import os
# post processing for transparency. then do resizing
# fuzz 11% removed too much if the dark pixels in the weps/armors. originally had 7% but chose 5.5% to remove the least pixels from the objects
# fuzz of 5.5% didnt work well on the helm invfhl. set fuzz to 4.5%
hd_pngs = glob.glob('png-hd/*hd.png')
for hd_png in hd_pngs:
print(f'starting to process: {os.path.basename(hd_png)}')
cmd = 'convert ' + hd_png + ' -bordercolor black -border 1x1 -fuzz 4.5% -transparent black -shave 1x1 .\\processed_items_D2R\\tmp.png'
subprocess.run(cmd, shell=True, check=True)
cmd = 'convert .\\processed_items_D2R\\tmp.png -alpha extract .\\processed_items_D2R\\tmp2.png'
subprocess.run(cmd, shell=True, check=True)
cmd = 'convert .\\processed_items_D2R\\tmp2.png -define connected-components:mean-color=true -define connected-components:area-threshold=200 -connected-components 4 .\\processed_items_D2R\\tmp3.png'
subprocess.run(cmd, shell=True, check=True)
cmd = 'convert .\\processed_items_D2R\\tmp3.png -blur 0x0.5 .\\processed_items_D2R\\tmp3-b.png'
subprocess.run(cmd, shell=True, check=True)
cmd = 'convert ' + hd_png + ' .\\processed_items_D2R\\tmp3-b.png -alpha off -compose copy_opacity -composite .\\processed_items_D2R\\' + os.path.basename(hd_png)[:-4] + '-trspr.png'
subprocess.run(cmd, shell=True, check=True)
time.sleep(0.25)
# size of D2R invgisu 98 x 392. size of D2 hd.png 112 x 448 scale 87.5% both x and y -v'
# tried with and without sharpening. No-sharpening looked better in-game
trsp_pngs = glob.glob('processed_items_D2R/*trspr.png')
for trsp_png in trsp_pngs:
print(f'starting to process: {os.path.basename(trsp_png)}')
cmd = 'convert ' + trsp_png + ' -resize 87.5% ' + trsp_png[:-4] + '-resize.png'
subprocess.run(cmd, shell=True, check=True)
time.sleep(0.25)
Using imagemagick
references: https://legacy.imagemagick.org/discourse-server/viewtopic.php?t=33589