index posts opinions portfolio


My posts about programming and things.
Date format is day/month/year because I'm sane.

Cropped Yuu's face too


Similar to Chito previously, I cropped out every Yuu face from Bloom Into You totalling 2325 images.

You can find them at https://gnupluslinux.com/yuu/ and download a zip containing every image sorted by chapter and ordered here.

Who cares for the details but, I used xbindkeys to create a shortcut that launches a script. This script uses scrot to take a cropped screenshot into a directory.

During the cropping of all faces I used feh to view images in order using `ls -1 -rt | xargs feh`. This will list the directory, show only file names, reverse the order and order them by modification time.

The file name is randomised, so to order them I needed to use the files modification time. To do this I used a simple bash script: `n=0; ls -tr | while read i; do n=$((n+1)); mv -- "$i" "$(printf %03d "$n").png"; done`. This renames every image in order (001.png, 002.png ...). I took care to use the `preserve` flag in cp (copy) to preserve the modification date when copying around.

Next I had to compress the images, to do this I used pngquant `pngquant --quality=65-80 * --ext .png --force`.

To prevent having to run the script manually in each chapter directory one at a time I ran them in a loop `for d in chapter*; do ( cd "$d" && ../../script.sh ); done`.

After compression the total file size for all images went from 138MB to 52MB.

Then I had to somehow turn these images files into html files. To do this I wrote a simple Python script that iterates through every chapter and image and generates the pages and navigation bars.

The python script:


import glob

outputdir = "out/"                                  # directory to output html
templatefile = "template.txt"                       # template file
imgglob = "*.png"                                   # glob for image files
nochapters = 45;                                    # number of chapters to include
localimgloc = "../"                                 # location of images on filesystem (../chapterx)
dirprefix = "chapter";                              # prefix for chapter directories
imgloc = "https://gnupluslinux.com/anime/yuu/";     # location of images
                                                    # final will be imgloc+dirprefix+chapternumber
                                                    # (https://gnupluslibux.com/anime/yuu/chapterx/001.png)

def getimgno(chapter):
    get number of images in chapter
    return  len(glob.glob1("%s/%s%s" % (localimgloc, dirprefix, str(chapter)), imgglob))

def generatenavbar(chapter):
    generate navigation bar for chapter
    bar = "Chapter: ";
    for p in range(1, nochapters+1):
        if p == chapter:
            # handle own chapter specially
            bar += "<strong>%s</strong> " % (str(p));
            bar += "<a href=\"%s%s.html\">%s</a> " % (dirprefix, str(p), str(p));
    return bar;

def generateimages(chapter):
    imgcount = getimgno(chapter);
    images = "";
    for p in range(1, imgcount+1):
        images += "<a href=\"%s/%s%s/%03d.png\"> <img src=\"%s/%s%s/%03d.png\" alt=\"Yuu face #%s\"></a>\n" \
        % (imgloc, dirprefix, str(chapter), p, imgloc, dirprefix, str(chapter), p, p);
    return images;

def generatepages():
    call all functions and generate/output final html
    for p in range(1, nochapters+1):
        navbar = generatenavbar(p);
        # read template into memory
        templatedata = "";
        with open (templatefile, 'r') as template:
            templatedata = template.read();
        #insert title
        templatedata = templatedata.replace("{TITLE}", "Yuu's face in chapter %s" % p); 
        # insert navbar
        templatedata = templatedata.replace("{NAVBAR}", navbar);
        #insert images
        images = generateimages(p);
        templatedata = templatedata.replace("{IMAGES}", images);
        # write to output file
        with open("%s/%s%s.html" % (outputdir, dirprefix, p), 'w') as out:

def main():

if __name__ == "__main__":

RSS feed
FSF member

page generated 25/6/2020 using websitegenerator in C