Split an image with multiple emojis/emotes on an even background into individual emojis/emotes
MIT License
If you ever made an emoji or an emote pack (for example for mastodon, a forum or a messenger) from a stock image sheet containing multiple cliparts, you know how tedious it is: You need to separate all of them from each other (which might be more difficult than just using a rectangle selection tool and cutting if they are somehow entangled); you need to crop them all to 512px (or whatever size your system needs); and you might need to make their background transparent and not forget to have a 16px (or smth) margin around the image.
MojiSplit automates this process for you - you give it some images with an even background and with one or more doodles, cliparts, icons or emojis on it, and it takes on the tasks detailed above for you. The result is a folder full of images of the individual elements in good emoji-size with good emoji-padding.
input.png
input.0.png
- input.5.png
The input image(s):
The output images:
(there are options to customize most of this)
Clone the repository (or download it, it doesn't matter)
Install imagemagick
(>=v6.9.12-14
)
See here for installation instructions if you don't already have it, and use this link instead of the one mentioned in the article to get the aforementioned version.
Navigate into the cloned folder and execute one of the command detailed in the Commands section.
inputs
directory, and the command(s) you would like to execute into command.sh
.finished-emojis
branch, which you can then pull or download from directly to get them.Basic usage:
./mojisplit.sh inp out
where inp
is the input and out
the output.
If inp
is an image file, only this image is used as an input, whereas if inp
is a directory, every image within this directory will be used as an input.
If out
is a PNG file name (ends with .png
or .PNG
), the resulting images will be merged into one image in a clear raster shape;
otherwise, the resulting images wil be stored in the directory out
(will be created if there is none yet, and overwrite any pre-existing directory if there is one under the same name already).
Optional arguments:
--background <some_color>
:
replaces a specific color with transparency in the beginning (smooth). This is necessary if your images aren't on a transparent background.
--background2 <some_color>
:
Specifies a color that will also be replaced with transparency in the end, but which will still be counted as non-transparent when cutting the image. You can use this color to show the tool that some non-connected parts of your image belong together by pre-editing the image to give them a connecting background in this color.
--pxsize <size_as_integer>
Allows you to customize the width and height of the resulting images. Defaults to 512px.
--padding <padding_as_integer>
Allows you to customize the padding between the resulting images' content and their border. Defaults to 16px.
--maxsize <max_size_of_the_resulting_images>
Some applications don't require a specific image width and height, but have a specific file size limit for their emojis. This option allows you to specify a max file size, and every output image will be scaled down and optimized to fit this file size.
Note that said optimization has optipng
as an optional dependency (as simple as sudo apt-get install optipng
on most systems);
otherwise, the max size will be ensured by resizing without any additional optimizations.
Values consist of an integer and KB
, MB
or GB
(without any space between number and unit) or no unit at all, which indicates that they are byte measurements.
This step is optimized to run in O(log2 n), where n
is the size of the image for which we want to find the biggest pixel size that fits within a given file size, in case you are wondering about the performance of this.
Please note:
The tool can take some minutes to run; please be patient with it!
The images I used for demonstration purposes in this repository are the following:
Aquatic plants used in the graphic above:
I used code from the following StackOverflow-answers and blog posts:
This code is licensed under the MIT license, except for the images used, which are not licensed at all since they are stock images that I am not allowed to re-license.
See here for the license text.