Skip to content

Commit

Permalink
Golden Frame 0.1.24
Browse files Browse the repository at this point in the history
  • Loading branch information
leomotors committed Mar 3, 2022
1 parent 86d41b4 commit 755357f
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 29 deletions.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
include assets/*
include src/*
include src/golden_frame/*
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ _work in progress, making a Python Package is so complex just like npm_
<img src="example/zhongxina_before.jpg" width = 200 /> **=**
<img src="example/zhongxina_after.png" width=200 />

PS. The original picture of golden frame is K-Pop Star (Search: กรอบทอง ทรงพระเจริญ in Google, there is many variant)
PS. The original picture of golden frame is K-Pop Star (Search: กรอบทอง ทรงพระเจริญ in Google, there are many variant)

### Command for Above Example

```bash
src/cli.py build golden_frame.png example/zhongxina_before.jpg --output=example/zhongxina_after.png
```

## Adding Images

Expand All @@ -24,3 +30,7 @@ file_name.json Schema
```

pos => x1,y1,x2,y2 ; Position to put pictures on, you can get these info using Paint

## TODO

- Upload to PyPi (This is so mucking hard, muck Python)
Binary file added assets/vladdy_daddy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions assets/vladdy_daddy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Vladimir Putin does not #StandWithUkraine but I do",
"pos": "172,456,369,803"
}
Binary file modified example/zhongxina_after.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 0 additions & 20 deletions golden_frame/cli.py

This file was deleted.

3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
name = golden_frame
description = Golden Frame Generator, Create Golden Frame for given images, it also supports other frame.
long_description = file: README.md
version = 0.1.10
long_description_content_type = text/markdown
version = 0.1.24
license = MIT
author = Leomotors
author_email = [email protected]
Expand Down
File renamed without changes.
39 changes: 39 additions & 0 deletions src/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3

import typer

from lib import PosOptions, buildFromPreset, listFrames

app = typer.Typer()


@app.command()
def build(frame_name: str, input: str, output="output.png", pos=PosOptions.CENTER):
"""Build the Golden Frame
Args:
frame_name (str): Name of Template Frame
input (str): Location of your Image
output (str, optional): Output Location. Defaults to "output.png".
pos (0 | 1 | 2, optional): Position Type CENTER = 0, START = 1, END = 2. Defaults to CENTER.
"""
buildFromPreset(frame_name, input, output, pos)


@app.command()
def list():
"""Print List of Available Frames
"""
print(listFrames())


def main():
app()


if __name__ == "__main__":
main()
53 changes: 46 additions & 7 deletions golden_frame/lib.py → src/lib.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Tuple, Union
from typing import Dict, List, Tuple, Union
import cv2
import numpy as np
import json
Expand Down Expand Up @@ -32,7 +32,7 @@ def resizeImage(
size: List[int],
posOption=PosOptions.CENTER
) -> np.ndarray:
px, py = pic.shape[0:2]
py, px = pic.shape[0:2]

ratio = max(size[0]/px, size[1]/py)

Expand Down Expand Up @@ -67,14 +67,53 @@ def buildGoldenFrame(
return frame


def loadConfig(name: str) -> str:
def loadConfig(name: str) -> Dict:
with open(".".join(name.split(".")[:-1]) + ".json") as f:
return json.load(f)["pos"]
return json.load(f)


def buildFromPreset(frame: str, image: str, out: str, opt=PosOptions.CENTER):
cfg = loadConfig(frame)
outim = buildGoldenFrame(cv2.imread(frame), cv2.imread(image),
# Temporary Solution
frame = f"./assets/{frame}"
out = f"./{out}"

try:
frameimg = cv2.imread(frame)
if not frameimg.data:
raise
except:
print(
f"ERROR: Cannot Read {frame}! Did you execute this script from correct location and frame name is correct?"
)
return

try:
inputimg = cv2.imread(image)
if not inputimg.data:
raise
except:
print(f"ERROR: Cannot Read Input Image {image}!")
return

cfg = loadConfig(frame)["pos"]
outim = buildGoldenFrame(frameimg, inputimg,
list(int(k) for k in cfg.split(",")), opt)

cv2.imwrite(out, outim)
try:
cv2.imwrite(out, outim)
except:
print(f"Error writing Image!")


def listFrames() -> str:
import os
items = list(filter(lambda x: not x.endswith(
".json"), os.listdir("./assets")))

text = f"There are {len(items)} frames available.\n"

for item in items:
cfg = loadConfig(f"./assets/{item}")
text += f"\n{item} : {cfg['name']}"

return text

0 comments on commit 755357f

Please sign in to comment.