Code Monkey home page Code Monkey logo

hexsticker's Introduction

hexsticker

Produce hexagon stickers automatically from an image in compliance with the Stickers Standard.

Installation

$ pip install hexsticker

After the installation step listed above, you will be able to use the hexsticker command:

$ hexsticker --help

Arch Linux

There is an AUR package available here: https://aur.archlinux.org/packages/hexsticker

For example with yay you can install it like this:

$ yay -S hexsticker

Requirements

  • Python 3.6+

Examples

Let's create a hexagon sticker for the Selinon project.

Here is the input image:

Selinon input logo

Let's create a hexagon sticker:

$ hexsticker selinon.png -o selinon-sticker-1.png
INFO:hexsticker.create:Writing output to 'selinon-sticker-1.png'

The resulting image is:

Selinon hexagon sticker sticker 1

As can be seen above, there are some parts cut off - let's add some padding to the image:

$ hexsticker input/selinon.png -o output/selinon-sticker-2.png --padding-size 25
INFO:hexsticker.create:Writing output to 'selinon-sticker-2.png'
Selinon hexagon sticker sticker 2

The padded part is white by default - that's why there are missing spikes of hexagon. Let's set color of padded area to the same color as background color of the original image:

$ hexsticker input/selinon.png -o output/selinon-sticker-3.png --padding-size 25 --padding-color '#66cfa7'
INFO:hexsticker.create:Writing output to 'selinon-sticker-3.png'
Selinon hexagon sticker sticker 3

Nice! What we could do next? Let's try to add a hexagon border:

$ hexsticker input/selinon.png -o output/selinon-sticker-4.png --padding-size 25 --padding-color '#66cfa7' --border-size 35
INFO:hexsticker.create:Writing output to 'selinon-sticker-4.png'
Selinon hexagon sticker sticker 4

Ehm, the default black one does not look that good in this case. Let's try some color that fits color scheme:

$ hexsticker input/selinon.png -o output/selinon-sticker-5.png --padding-size 25 --padding-color '#66cfa7' --border-size 35 --border-color '#197a9f'
INFO:hexsticker.create:Writing output to 'selinon-sticker-5.png'
Selinon hexagon sticker sticker 5

Note that the edges of the hexagon look a little jagged. You can add --supersample 2 to the previous command to remedy this. The number given sets the scale factor to use. Greater values result in a smoother result, at the expense of higher memory usage. This effect has diminishing returns; usually a value of 2 is enough for a nice result and going higher than 4 does not make much noticeable improvement.

As you can see, this tool can automate creation of hexagon stickers so they respect the hexagon standard. Feel free to additionally adjust the resulting image of your logo or the input image.

This tool supports only raster graphics.

Running from repo

To run hexsticker from repository run the following commands:

$ git clone https://github.com/fridex/hexsticker  # or use ssh
$ cd hexsticker
$ pip3 install -r requirements.txt --user
$ export PYTHONPATH='.'
$ ./hexsticker-cli --help

hexsticker's People

Contributors

ambv avatar backwardspy avatar fridex avatar sionleroux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hexsticker's Issues

Doesn't work with JPGs

Hi, the README says:

This tool supports only raster graphics.

All the examples show using PNGs but I thought I'd try a JPG and it crashes the program:

hexsticker dp.jpg 
INFO:hexsticker.create:Writing output to 'dp-sticker.jpg'
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/PIL/JpegImagePlugin.py", line 643, in _save
    rawmode = RAWMODE[im.mode]
KeyError: 'RGBA'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/hexsticker/create.py", line 206, in create_hexsticker
    img.save(output_file, output_file_type.upper())
  File "/usr/lib/python3.10/site-packages/PIL/Image.py", line 2431, in save
    save_handler(self, fp, filename)
  File "/usr/lib/python3.10/site-packages/PIL/JpegImagePlugin.py", line 646, in _save
    raise OSError(msg) from e
OSError: cannot write mode RGBA as JPEG

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/bin/hexsticker", line 33, in <module>
    sys.exit(load_entry_point('hexsticker==1.2.0', 'console_scripts', 'hexsticker')())
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/hexsticker/cli.py", line 69, in hexsticker
    create_hexsticker(**options)
  File "/usr/lib/python3.10/site-packages/hexsticker/create.py", line 208, in create_hexsticker
    raise exceptions.SaveError(f"Failed to save resulting image: {str(exc)}") from exc
hexsticker.exception.SaveError: Failed to save resulting image: cannot write mode RGBA as JPEG

Have I made a mistake, e.g. missed installing a library? Or does the program not support JPEG? I'd guess the latter because the stack trace mentions saving RGBA as JPEG, and I suppose the A in RGBA is because of the transparent background after the hexagon is cut out and JPEGs don't support transparency. Maybe it would be good to add a file type check at the beginning of the program to make sure the user provides an input filetype that will support transparency in the output?

Packaged for Archlinux

Hi I made an AUR package for version 1.2.0 so that it's easy to install on Arch Linux: https://aur.archlinux.org/packages/hexsticker

For example with yay you can install it like this:

yay -S hexsticker

Maybe it would be useful to mention this at the bottom of the README, but if not then it's okay to close this issue, I just wanted to give a heads up ๐Ÿ˜‰

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.