Skip to content

Commit

Permalink
Update readme, and fix setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
HarryPeach committed Jun 19, 2019
1 parent 09d8538 commit e7d9818
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 8 deletions.
16 changes: 16 additions & 0 deletions README.md
@@ -1,9 +1,19 @@
# emojimage

![Test Image](https://user-images.githubusercontent.com/4750998/59804960-ca430000-92e7-11e9-9207-8bfa3870fcf3.png?s=200)
![Emoji'd Image](https://user-images.githubusercontent.com/4750998/59804970-d464fe80-92e7-11e9-89cc-5c9f194aa3cb.png?s=200)

emojimage is a Python program to convert an image into a collage of emojis.

## Usage

### From the Command Line

1. Install the package
2. Use ```python -m emojimage <input>.jpg```

### As a Python library

TODO

## FAQ
Expand All @@ -12,6 +22,12 @@ TODO

> The emojis are from JoyPixels.
## Todo

1. Speed up the program, moderate size images can take 5+ minutes to process, dependent on emoji size.
2. More documentation and ease of use changes
3. More customizablility through command-line arguments

## License

Copyright (C) 2019 Harry Peach
Expand Down
Binary file removed composite.png
Binary file not shown.
11 changes: 7 additions & 4 deletions emojimage/__main__.py
@@ -1,6 +1,7 @@
import logging
import argparse
import os
import random
from PIL import Image
from .metafile import (generate_metafile, does_metafile_exist, populate_emoji_dictionary, emoji_dictionary,
get_closest_colour)
Expand All @@ -20,6 +21,10 @@ def create_collage(path, image_scale=1, emoji_size=16):
"""
image = Image.open(path)

# Populate the emoji dictionary if it is empty
if not emoji_dictionary:
populate_emoji_dictionary()

# Resize the image if a scale is specified
if image_scale != 1:
image = resize_image(image, image_scale)
Expand All @@ -44,7 +49,7 @@ def create_collage(path, image_scale=1, emoji_size=16):
temp_avg = get_average_color(temp_image)

offset = ((width//emojis_x) * x, (height//emojis_y) * y)
emoji_image = get_emoji_image("face-with-tears-of-joy")
emoji_image = get_emoji_image(random.choice(get_closest_colour(get_average_color(temp_image))))
composite_image.paste(emoji_image.resize((emoji_size, emoji_size)), offset)

# Save the final image
Expand Down Expand Up @@ -73,6 +78,4 @@ def create_collage(path, image_scale=1, emoji_size=16):
logger.debug("Emoji metafile already existed, and so was not created")

# TODO implement arguments for width, height, and emoji size
# create_collage(args.image_input)
populate_emoji_dictionary()
get_closest_colour((123, 123, 253))
create_collage(args.image_input)
6 changes: 3 additions & 3 deletions emojimage/metafile.py
Expand Up @@ -43,17 +43,17 @@ def does_metafile_exist():
return os.path.isfile(get_metafile_path())


def get_closest_colour(rgb):
def get_closest_colour(rgba):
"""Takes in a colour and returns the closest emojis to that colour
Adapted from https://stackoverflow.com/a/54242348
Arguments:
rgb {tuple} -- The red, green, and blue values of the input
rgba {tuple} -- The red, green, blue, and alpha values of the input
Returns:
list -- The emoji/emojis that are closest to the given colour
"""
r, g, b = rgb
r, g, b, a = rgba
colour_diffs = []
for colour in emoji_dictionary.keys():
cr, cg, cb = colour
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -11,6 +11,7 @@
EMAIL = "harrypeach1999@gmail.com"
AUTHOR = "Harry Peach"
REQUIRES_PYTHON = ">=3.7.0"
VERSION = "1.0.0"

REQUIRED = [
"pillow"
Expand Down Expand Up @@ -88,7 +89,6 @@ def run(self):
'console_scripts': ['mycli=emojimage:cli'],
},
install_requires=REQUIRED,
extras_require=EXTRAS,
include_package_data=True,
license='GPLv3',
classifiers=[
Expand Down
Binary file removed test_image.jpg
Binary file not shown.
Binary file added test_input.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_output.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e7d9818

Please sign in to comment.