It was a dark and stormy night. In a room humid with sweat, temperature reached 29°C. The night slipped from 3rd to 4th, it was March of 2022, Friday. I had school the other day, and yet, I was up all night trying to extract images from this japanese VN.
This was a curious case. After somehow extracting the the files from this absurd .arc
format, I was at a loss. Each animations, as it seemed, was a long image file with each animation frame placed side to side. Each frame measuring 960 pixels
wide.
I wanted those animations bad. But manually cutting up each frame perfectly was near about impossible. So, I did what every self proclaimed programmer would. I considered automating it all with code.
This project is a culmination of a lot of things. Call it stubbornness, or overconfidence, I was sure it was just a matter of an hour. "1 or 2 am at most", I thought, and having compiled a few scripts in Autoit before, I got started.
🔴 Batch files are used for automation. Maybe I can write something up? (I knew 0 thing about batch scripting)
🟠 Batch files support drag n' drop. I need drag n' drop. Ok. No more Autoit then.
🟡 But then how do it split it? Batch files cannot process image. I need something else
🟢 Okay, I found this split-image project on github. How do I use it? Oooookay it's in python (why does it have to be python)
🔵 Fine I can pass some arguments into it's cli via the batch file.
🟣 So I have to mention the number of splits I want, but... batch files can't process image. I need to read the image width, and find the number of splits. And, I can't write python 🥲
🟤 Well, Autoit it is then. I should read the image, find possible splits, and then pass that information to the batch file which will then pass that to split.py
⚫ BUT how do I pass data between autoit and batch file? * an hour of brute force later* FINE text file it is.
⚪ So there I was. Hours in and a project with a million pieces.
- User Drag n' Drops an image to
START.bat
STRAT.bat
renames the file to replace space with underscore (space causes issues while handling image in autoit). And passes control over tosplit.bat
.
split.bat
creates a new folder with the same name as the image, and moves the image into that folder.
split.bat
creates a text file and writes the address of the image to the first line.
split.bat
startswidth.au3
(or .exe).
width.au3
reads the text file to get the location of the image. It then calculates the number of horizontal splits it can perform based on the split width hardcoded in the script. It then writes that number in the first line of the text file. Control is then returned tosplit.bat
Vertical splits are NOT performed as it was not required for my use case
split.bat
then takes both, the image and the possible split integer, and passes it tosplit.py
.
split.py
can perform both horizontal and vertical splitting. Bases on requirement, it horizontally splits the image.
- The results are present in a folder as the same name as the imput image, just with underscores in place of spaces.
|
---|
By default the size of each horizontal split is 960 pixel. There is no vertical splits.
Run :
You'll need Autoit runtime and Python installed to use the scripts directly from code. Drag and drop the require image to START.bat
to use it. Launching the batch files directly do nothing.
Compile :
Autoit provides a direct tool to convert to .exe and you may use pyinstaller to convert the python script to an .exe as well. The batch files need not be modified.
NOTE: I feel like I need to say it every time, but Windows likes to flag almost everything I write as virus. No, I am not a malware author. The code is open for you to inspect. Yes, it is a false positive.
The package present in the release contains all the scripts in a runnable format, i.e. as .exe
or .bat
.
width.exe
has hard coded size of horizontal split set to 960 pixel
and you cannot change that from the execuatble. If you plan to use it for other sizes, I recommend downloading and separately recompiling width.au3
with your own custom width value.