This code is setup to create Multilingual GIFs/Images for increasing the awareness of COVID-19 pandemic.
.
├── code
│ ├── data -> ../data
│ ├── out -> ../out/
├── data
│ ├── fonts
│ │ └── indic
│ └── src
├── nbs
│ ├── code -> ../code/
│ ├── data -> ../data/
│ └── out -> ../out/
└── out
├── gif
└── image
nbs/ - Experimental code
code/ - Scripts to run
data/ - Data files
- data/fonts - Fonts used in creating the GIFs, add more font styles here
- data/src - Source of Template GIFs, add more templates for GIFs here
out/ - Stores the newly baked GIFs
Resources
Fonts . Download & extract it inside the data/
dir.
Google Sheet Download as CSV & place it inside the data/
dir.
For Ubuntu, use conda env create -f environment.yml
.
For Windows, most of the code setup should work. Will soon update with yml
file.
-
Select a GIF or Image that you wish to translate to multiple languages, then, download inside
data/src/
folder and save as{filename}.{suffix}
-
Move into the
code
dir.
cd code
- Split the GIF into frames
python split_merge.py split -p data/src/{filename}.gif
- Clean the slate, remove texts from the GIF using Photoshop/GIMP/Paint or if you have a designer friend, take their help!
OR
To avoid the above steps, this process is automated to a certain extent. Will try to automate completely. Here's you do it: In your .json file, include the pixel location of background color you want.
"T1": { "frames": [1], "box": [374, 38, 1145, 95], "color": "white",__"bgloc":[232,30]__}, "T2": { "frames": [1], "box": [344, 28, 1445, 55], "color": "white"}
-
Create a template JSON file, name it {filename}.json & put inside the
data
directory. For eg: look intodata/social-distance.json
.
Again take the help of a designer friend or use application like Photoshop/GIMP to find the box coordinates(left, top, right, bottom)
-
Merge the frames back into GIF
python split_merge.py merge -p data/src/frames/{filename} -n {filename}.{suffix}
- Create the translated GIF/Image files
python parser.py -p data/src/{filename}.{suffix} -l hindi,odia,tamil...
- Create Mp4 files for GIF to share with others
python gif2mp4 out/gif/{filename}
cd code/
make splitgif filename='data/src/social-distance.gif' #Only for GIFs.
make translation filename='data/src/social-distance.gif'
make mp4
# Note this above approach works only when the CSV name aligns with that of gif's/png's name.
# For ex: covid-spread - {social-distance}.csv with {social-distance}.gif
make gif
:
- Reads a CSV file
- Reads the template (.json) file for the GIF
- Calls
gifware
orimgware
to create the content
make mp4
:
- Converts the
gif
tomp4
(Execute this only when you want to create GIFs, not for images)
- Put the GIF or Image inside the
data/src/
dir, and callpython splitter {path_to_file}
. This will split GIFs into individial frames & store it insidedata/src/frames/
. - Use the frames as reference and create a template file, for eg: Template file for
data/src/social-distance.gif
file isdata/social-distance.json
.
{
"num_frames": 34,
"duration": "[0.12] * 26 + [1] + [1] + [0.5] + [2.5] * 4",
"tags": {
"T1": { "frames": [27], "box": [515, 275, 870, 460], "color": "black"},
"T2": { "frames": [29, 30, 31, 32, 33], "box": [186, 102, 450, 255], "color": "black"},
"T3": { "frames": [30, 31, 32, 33], "box": [520, 107, 756, 255], "color": "black"},
"T4": { "frames": [31, 32, 33], "box": [405, 565, 683, 674], "color": "black"},
"T5": { "frames": [32, 33], "box": [818, 641, 1005,738], "color": "black"}
}
}
num_frames - Total number of frames in the GIF, zero indexed duration - List, how much time in seconds should a frame appear for in the GIF tags:
- T$ - unique id to tag that maps it to the Google Sheet
- frames - Frame number in which the Tag is supposed to appear
- box - [left, top, right, bottom] position of the text (Use GIMP, Photoshop or Matplotlib axis to find the positions)
- color - color of the text
We write on a GIF with empty template. For example, look at data/src/social-distance.gif
.