You can run this script from the cmd line and pass files as arguments, but what I do is select image file(s) in xyPlorer, then call this script and pass the selected items as arguments. It spits out a single .ico file for each image I passed, so making a bunch of icons in one go is painless.
Code: Select all
Create Icons|run lax("C:\Path\to\WinPython Interpreter.exe" "C:\Path\to\script\CreateIcons.py" <selitems>)
This script uses ImageMagick, so you'll need to download it and point the script to convert.exe. I recommend downloading the portable version of ImageMagick, just search for it on their downloads page: ImageMagick
Code: Select all
from pathlib import Path
import subprocess
import sys
# Full Path to "ImageMagick/convert.exe"
# example: Path('C:/Program Files/ImageMagick/convert.exe')
imagemagick = Path(sys.argv[0]).resolve().parents[2] / 'Command/ImageMagick/convert.exe'
for argument in sys.argv[1:]:
file = Path(argument).resolve()
output_filename = file.parent / f'{file.stem}.ico'
if file.suffix == '.svg':
command = [
str(imagemagick),
'-density',
'600',
'-background',
'none',
str(file),
'-resize',
'256x256',
'-define',
'icon:auto-resize=256,128,48,32,24,16',
str(output_filename)
]
elif file.suffix == '.png':
command = [
str(imagemagick),
'-background',
'none',
str(file),
'-define',
'icon:auto-resize=256,128,48,32,24,16',
str(output_filename)
]
else:
print('Not a supported filetype, exiting...')
sys.exit()
subprocess.Popen(command)
sys.exit()