Skip to content

Commit

Permalink
Fixed module setup and external usage
Browse files Browse the repository at this point in the history
  • Loading branch information
HarryPeach committed Jun 20, 2019
1 parent 4b648f0 commit 438dfee
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
17 changes: 17 additions & 0 deletions .vscode/launch.json
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "emojimage",
"args": [
"test_input.jpg", "-d"
]
}
]
}
9 changes: 5 additions & 4 deletions emojimage/img_utils.py
Expand Up @@ -13,10 +13,11 @@ def get_emoji_image(name):
Returns:
PIL.Image -- The image of the emoji, None if emoji does not exist.
"""
with resources.path("emojimage", "emoji") as p:
for emoji_path in p.glob(name + ".*"):
return Image.open(emoji_path)
return None
for x in resources.contents("emojimage.emoji"):
if name in x:
with resources.path("emojimage.emoji", x) as p:
return Image.open(p).copy()
return None


def resize_image(image, scale):
Expand Down
30 changes: 11 additions & 19 deletions emojimage/metafile.py
Expand Up @@ -68,22 +68,14 @@ def generate_metafile():
logger.info("Generating emoji metafile")
logger.debug("Opening emoji resource folder")

# logger.debug("Opening metafile")
# with open(get_metafile_path(), 'w', newline='\n') as file:
# csvwriter = csv.writer(file, delimiter=',')
# logger.debug("Writing emoji metadata")
# for x in resources.contents("emojimage.emoji"):
# with resources.path("emojimage.emoji", x) as p:
# image = Image.open(p)
# r, g, b, a = get_average_color(image)
# csvwriter.writerow([os.path.splitext(x)[0], r, g, b])

with resources.path("emojimage", "emoji") as p:
logger.debug("Opening metafile")
with open(get_metafile_path(), "w", newline='\n') as file:
logger.debug("Writing emoji metadata")
csvwriter = csv.writer(file, delimiter=',')
for emoji_path in p.glob("*"):
image = Image.open(emoji_path)
r, g, b, a = get_average_color(image)
csvwriter.writerow([emoji_path.stem, r, g, b])
logger.debug("Opening metafile")
with open(get_metafile_path(), 'w', newline='\n') as file:
csvwriter = csv.writer(file, delimiter=',')
logger.debug("Writing emoji metadata")
for x in resources.contents("emojimage.emoji"):
if x.startswith("__"):
continue
with resources.path("emojimage.emoji", x) as p:
image = Image.open(p)
r, g, b, a = get_average_color(image)
csvwriter.writerow([os.path.splitext(x)[0], r, g, b])

0 comments on commit 438dfee

Please sign in to comment.