Coder Social home page Coder Social logo

icons-asset-generator's Introduction

Icons Asset Generator for OmniGraffle and diagrams.net

Convert SVG images into:

Features:

  • parametrize connection points (magnets)
  • filter images by name
  • format icon names

See diagrams-aws-icons with generated AWS Architecture Icons library for diagrams.net.

Idea based on script from AWS-OmniGraffle-Stencils

Usage

Requires Python 3.8+ and Poetry.

Install dependencies in virtual env:

poetry install

Run:

poetry run icons-asset-generator \
    --path ./icons-directory [<common-args>] \
    <target-application> [<application-args>]

where <target-application> is one of:

  • diagrams.net
  • omnigraffle

Common options

  • --path - input files directory path
  • --output - output directory path (default: ./library)
  • --filename-includes - strings to filter image file name by, taking only those which contains them all; accepts multiple arguments
  • --filename-excludes - strings to filter image file name by, taking only those which do not contain any of them; accepts multiple arguments
  • --image-name-remove - strings to be removed from image file name (default: . - _); accepts multiple arguments
  • --library-name-remove - strings to be removed from library file name (default: . - _); accepts multiple arguments
  • --no-vertex-magnets - don't create connection points on vertices (corners)
  • --side-magnets - number of connection points for each side (default: 5)
  • --labels - add label with name to the images
  • --help - display help

All SVG files from the given path will be added to the output asset, recursively.

If you provide arguments accepting multiple arguments, put the --path argument last so the parser knows where arguments stop and parses <target-application> parameter correctly.

Diagrams.net specific options

  • --size - resize images to target size; accepts argument in format TYPE=NUMBER where TYPE is one of width, height, longest

OmniGraffle specific options

  • --text-output - write OmniGraffle data file as text instead of binary

If SVG files are grouped into directories, each root-level directory will become a separate group in the output Stencil.

For example, this structure:

svg/
├── Group 1/
│   ├── icon1.svg
│   ├── icon2.svg
│   ├── icon3.svg
└── Group 2/
    ├── icon4.svg
    └── Subgroup
        └── icon5.svg

would produce a Stencil with Group 1 with 3 icons and Group 2 with 2 icons.

Example: AWS Architecture Icons

To generate icons from AWS Architecture Icons download SVG zip file (example: Asset-Package_04302022) and unpack it.

Run:

poetry run icons-asset-generator \
    --filename-includes _48 \
    --filename-excludes Dark \
    --image-name-remove Light Arch_ Res_ _48 . - _  \
    --library-name-remove  . - _ \
    --path "./Asset-Package_04302022" \
    diagrams.net

Open diagrams.net and load created asset from the ./library directory.

icons-asset-generator's People

Contributors

lfittl avatar m-radzikowski avatar

Stargazers

 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  avatar

icons-asset-generator's Issues

specifying a non-empty output dir erases the entire contents of that dir without warning

I just had an oops moment when I misunderstood that the --output parameter requires a non-existing or empty folder.

I ran the following command:

poetry run icons-asset-generator \
--path ~/Downloads/affinity/svg \
--image-name-remove c sq \
--output ~/Desktop \
diagrams.net

I got an error message that the dir wasn't empty, and then the program aborted. To my surprise, my entire ~/Desktop directory had been nuked. Luckily I had a backup, but this could easily be catastrophic.

I think this is the problematic code:

import os
import shutil
def create_output_dir(dir_name) -> None:
shutil.rmtree(dir_name, ignore_errors=True)
os.mkdir(dir_name)

Maybe a check for empty dir could be used instead (this is just an example)

import os
import shutil

from icons_asset_generator.util.logger import get_logger
logger = get_logger(__name__)

def is_directory_empty(path):
    if not os.path.isdir(path):
        raise ValueError("Invalid directory path")
    with os.scandir(path) as entries:
        for entry in entries:
            if not entry.name.startswith('.'):
                return False
    return True

def create_output_dir(dir_name) -> None:
    try:
        os.makedirs(dir_name, exist_ok=True)
    except Exception as e:
        logger.error(repr(e))
        exit(1) 
    try:
        assert(is_directory_empty(dir_name))
    except AssertionError:
        logger.error(f'directory {dir_name} is not empty!')
        exit(1)

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.