Skip to content

gramener/bhasha

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Giffer : Templatize GIFs.

Why?

This code is setup to create Multilingual GIFs/Images for increasing the awareness of COVID-19 pandemic.

Folder structure

.
├── 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.

Dependencies:

For Ubuntu, use conda env create -f environment.yml.
For Windows, most of the code setup should work. Will soon update with yml file.

Process

  1. Select a GIF or Image that you wish to translate to multiple languages, then, download inside data/src/ folder and save as {filename}.{suffix}

  2. Move into the code dir.

cd code
  1. Split the GIF into frames
python split_merge.py split -p data/src/{filename}.gif
  1. 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"}

  1. Create a template JSON file, name it {filename}.json & put inside the data directory. For eg: look into data/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)

  2. Merge the frames back into GIF

python split_merge.py merge -p data/src/frames/{filename} -n {filename}.{suffix}
  1. Create the translated GIF/Image files
python parser.py -p data/src/{filename}.{suffix} -l hindi,odia,tamil...
  1. Create Mp4 files for GIF to share with others
python gif2mp4 out/gif/{filename}

How to run?

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 or imgware to create the content

make mp4:

  • Converts the gif to mp4 (Execute this only when you want to create GIFs, not for images)

How to create a template file?

  • Put the GIF or Image inside the data/src/ dir, and call python splitter {path_to_file}. This will split GIFs into individial frames & store it inside data/src/frames/.
  • Use the frames as reference and create a template file, for eg: Template file for data/src/social-distance.gif file is data/social-distance.json.

Structure

{
  "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

How it Works?

We write on a GIF with empty template. For example, look at data/src/social-distance.gif.

Demo

Giffer

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages