diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4d2a36f..b16ac62 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,51 +9,50 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - ref: ${{ github.head_ref }} # checkout the correct branch name - fetch-depth: 0 # fetch the whole repo history + - name: Checkout code + uses: actions/checkout@v3 + with: + ref: ${{ github.head_ref }} # checkout the correct branch name + fetch-depth: 0 # fetch the whole repo history - - name: Git Version - id: version - uses: codacy/git-version@2.7.1 - with: - release-branch: main # default is master - prefix : v - + - name: Git Version + id: version + uses: codacy/git-version@2.7.1 + with: + release-branch: main # default is master + prefix: v - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.x + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.x - - name: Install PyInstaller - run: pip install pyinstaller - - name : requirements - run: pip install pillow image tk tqdm - - name: Build Binary - run: pyinstaller main.py --onefile + - name: Install PyInstaller + run: pip install pyinstaller + - name: requirements + run: pip install pillow image tk tqdm + - name: Build Binary + run: pyinstaller main.py --onefile - - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.MY_TOKEN }} - with: - tag_name: ${{ steps.version.outputs.version }} # version tag to create - release_name: Ascii art generator ${{ steps.version.outputs.version }} # name of the release - body: 'New release : fixed bugs, new functionalitys, and more...' # description of the release - draft: false # set to true if you want to create a draft release instead of a published one - prerelease: false # set to true if this is a pre-release + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.MY_TOKEN }} + with: + tag_name: ${{ steps.version.outputs.version }} # version tag to create + release_name: Ascii art generator ${{ steps.version.outputs.version }} # name of the release + body: "New release : fixed bugs, new functionalitys, and more..." # description of the release + draft: false # set to true if you want to create a draft release instead of a published one + prerelease: false # set to true if this is a pre-release - - name: Upload Binary - id: upload-release-assets - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.MY_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./dist/main # path to the binary file - asset_name: ascii-art-generator # name of the binary file in the release - asset_content_type: application/octet-stream # content type of the binary file + - name: Upload Binary + id: upload-release-assets + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.MY_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./dist/main # path to the binary file + asset_name: ascii-art-generator # name of the binary file in the release + asset_content_type: application/octet-stream # content type of the binary file diff --git a/main.py b/main.py index f41da72..bf6491d 100755 --- a/main.py +++ b/main.py @@ -1,4 +1,3 @@ - #!/usr/bin/env python3 import argparse from tkinter import * @@ -9,7 +8,6 @@ def reduce_resolution(image_path, new_height): with Image.open(image_path) as img: - width, height = img.size reduction_factor = new_height / height @@ -22,7 +20,6 @@ def reduce_resolution(image_path, new_height): def convert2D(liste): - list2d = [] lines = [] @@ -30,8 +27,7 @@ def convert2D(liste): ii = 0 for i in liste: - - if ii >= im.width-1: + if ii >= im.width - 1: ii = 0 list2d.append(lines) lines = [] @@ -45,11 +41,16 @@ def convert2D(liste): parser = argparse.ArgumentParser( - description='Transform an image into asciis characters.') -parser.add_argument('-p', '--picture', - help='Picture file to use.', required=True) + description="Transform an image into asciis characters." +) +parser.add_argument("-p", "--picture", help="Picture file to use.", required=True) parser.add_argument( - '-he', '--height', help='Ascii art result height (In numbers of characters)', required=False, default=500) + "-he", + "--height", + help="Ascii art result height (In numbers of characters)", + required=False, + default=500, +) args = parser.parse_args() @@ -63,8 +64,25 @@ def convert2D(liste): pixelles = convert2D(list(im.getdata())) -CHARS = ['ㅤㅤㅤ', '+++', '***', '===', '%%%', '###', '@@@', '&&&', - '$$$', 'MMM', 'WWW', '888', '▌▌▌', '▬▬▬', '▒▒▒', '███', '▓▓▓'] +CHARS = [ + "ㅤㅤㅤ", + "+++", + "***", + "===", + "%%%", + "###", + "@@@", + "&&&", + "$$$", + "MMM", + "WWW", + "888", + "▌▌▌", + "▬▬▬", + "▒▒▒", + "███", + "▓▓▓", +] result = "" @@ -72,11 +90,10 @@ def convert2D(liste): test = 0 for i in tqdm(range(0, len(pixelles)), desc="Loading..."): - result += "\n" for ii in range(0, len(pixelles[i])): - result += CHARS[int(pixelles[i][ii]//(256/len(CHARS)))] + result += CHARS[int(pixelles[i][ii] // (256 / len(CHARS)))] root = Tk() @@ -93,18 +110,18 @@ def convert2D(liste): text = Text(root, height=im.height, wrap=NONE) text.grid(row=0, column=0, sticky=EW) -text.config(font=('Helvetica bold', 1)) +text.config(font=("Helvetica bold", 1)) -scrollbarVert = Scrollbar(root, orient='vertical', command=text.yview) +scrollbarVert = Scrollbar(root, orient="vertical", command=text.yview) scrollbarVert.grid(row=0, column=1, sticky=NS) -scrollbarHor = Scrollbar(root, orient='horizontal', command=text.xview) +scrollbarHor = Scrollbar(root, orient="horizontal", command=text.xview) scrollbarHor.grid(row=1, column=0, sticky=EW) -text['yscrollcommand'] = scrollbarVert.set -text['xscrollcommand'] = scrollbarHor.set +text["yscrollcommand"] = scrollbarVert.set +text["xscrollcommand"] = scrollbarHor.set text.insert(1.0, result)