diff --git a/README.md b/README.md index 61e1b94..a56181b 100644 --- a/README.md +++ b/README.md @@ -33,10 +33,16 @@ Questa repository contiene i seguenti script: Dipendenze: `PyPDF2` +- `pokepixel` — [@Fran314](https://git.phc.dm.unipi.it/Fran314) + + Permette di "disegnare" a terminale degli sprite di pokemon presi da [questa repo](https://github.com/msikma/pokesprite/) + + Ad esempio `pokepixel latias.png` cerca un file di nome `latias.png` nella cartella corrente. Se lo trova renderizza quello, altrimenti lo cerca nella repo linkata. Per ora funziona solo con i pokemon fino alla 7a gen non shiny + - `gobbino` — [@BachoSeven](https://git.phc.dm.unipi.it/BachoSeven) + [@Dilillo](http://poisson.phc.dm.unipi.it/~dilillo/Vario/index.html) Permette di scaricare video e/o pdf di qualsiasi corso presente sul sito del professor Gobbino - `pdfcompress` — [@aziis98](https://git.phc.dm.unipi.it/aziis98) (script preso in prestito [da questa repo](https://git.phc.dm.unipi.it/aziis98/chatgpt-scripts/src/branch/main/bin/pdfcompress2)) - Comprime un PDF vettorizzato (ad esempio note scritte su un iPad) utilizzando poppler (file di ~100MB diventa tranquillamente di ~10MB) \ No newline at end of file + Comprime un PDF vettorizzato (ad esempio note scritte su un iPad) utilizzando poppler (file di ~100MB diventa tranquillamente di ~10MB) diff --git a/pokepixel b/pokepixel new file mode 100755 index 0000000..252ae2e --- /dev/null +++ b/pokepixel @@ -0,0 +1,74 @@ +#!/usr/bin/env python + +import requests +from PIL import Image +import sys +import os + +img_url = 'https://blog.finxter.com/wp-content/uploads/2022/04/greenland_02a.jpg' + +if __name__ == "__main__": + if len(sys.argv) < 2: + print("No file given as argument") + exit(1) + + input_file = sys.argv[1] + img = Image.new("RGBA", (0,0)) # create empty image to override + if os.path.isfile(input_file): + img = Image.open(input_file) + if not os.path.isfile(input_file): + img_url = f'https://raw.githubusercontent.com/msikma/pokesprite/master/pokemon-gen7x/regular/{input_file}' + img = Image.open(requests.get(img_url, stream = True).raw) + + output = "" + last_color = "" + + bb = [0, 0, img.size[0] - 1, img.size[1] - 1] + while bb[0] < img.size[0] - 1: + if any([img.getpixel((bb[0], y))[3] != 0 for y in range(img.size[1])]): + break + else: + bb[0] += 1 + + while bb[1] < img.size[1] - 1: + if any([img.getpixel((x, bb[1]))[3] != 0 for x in range(img.size[0])]): + break + else: + bb[1] += 1 + + while bb[2] > bb[0]: + if any([img.getpixel((bb[2], y))[3] != 0 for y in range(img.size[1])]): + break + else: + bb[2] -= 1 + + while bb[3] > bb[1]: + if any([img.getpixel((x, bb[3]))[3] != 0 for x in range(img.size[0])]): + break + else: + bb[3] -= 1 + + # output += "\n\n" + for y in range(bb[1], bb[3] + 1): + # output += " " + for x in range(bb[0], bb[2] + 1): + [r, g, b, a] = img.getpixel((x, y)) + if a > 0: + curr_color = f'48;2;{r};{g};{b}' + else: + curr_color = "0" + + if curr_color != last_color: + output += f'\033[{curr_color}m' + last_color = curr_color + + output += " " + if last_color != "0": + output += "\033[0m" + last_color = "0" + + if y < bb[3]: + output += "\n" + + # output += "\n" + print(output)