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.
More on Image -> Output
The input image(s):
- The tool expects your image to have a uniform background (ideally transparent; see here for more options about this).
- Different parts of your image may have overlapping bounding boxes.
- Elements in your image may have holes in them.
The output images:
- transparent background.
- 512x512 px large (a power of two and exactly the size that Signal messenger wants for stickers, coincidentally).
- 16px padding between their border and the border of their contents.
(there are options to customize most of this)
-
Clone the repository (or download it, it doesn't matter)
-
Install
imagemagick
(>=v6.9.12-14
) -
Navigate into the cloned folder and execute one of the command detailed in the Commands section.
- Fork the repository & clone your fork
- Make your fork an independent copy (in the GitHub repository settings) and make it private
- Add the images you would like the convert to the
inputs
directory, and the command(s) you would like to execute intocommand.sh
. - Push these changes.
- The finished emojis should now be in the
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 assudo 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
orGB
(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)
, wheren
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:
- tropical plants png from pngtree.com
- Floral vector created by Harryarts - www.freepik.com
- Hand drawn arrow by Marcel Dornis from the Noun Project for the array used in the reddit post on r/bash and the array in the graphic above.
Aquatic plants used in the graphic above:
- seaweed clipart png from pngtree.com
- coral clipart png from pngtree.com
- cartoon png from pngtree.com
- under the sea clipart png from pngtree.com
- coral clipart png from pngtree.com
- child creature png from pngtree.com
- creative simplicity png from pngtree.com
- under the sea clipart png from pngtree.com
I used code from the following StackOverflow-answers and blog posts:
- This answer on how to get masks for the individual objects in the picture.
- This answer on how to mask (I didn't take code from it, though).
- This answer on how to convert a color to alpha (including its code).
- This answer on how to fit an image into a square (including its code).
- This answer on how to extract extended arguments from the command line.
- This blog post on how to make cleanup functions for bash scripts.
- I postet about this project on r/bash on Reddit.
- I made more or less the same post (different comments, though) on r/coolgithubprojects.
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.