7,599 bytes added
, 10:42, 26 December 2013
The sugariconify.py script converts SVGs into the format required for Sugar icons, adding the necessary stroke and fill entities. This is a Python script, and as such requires Python to run.
==<big>Usage</big>==
sugariconify.py [-ceghipv] [-s stroke_hex] [-f fill_hex] [-m | -o ] [-d directory] input.svg
==<big>Description</big>==
This script will create Sugar-compatible SVG icons from input.svg by adding the appropriate stroke and fill entities. It has two primary modes of operation: single-icon and icon set. For additional information about creating an SVG suitable for passing as the input to this script, see the tutorial on Making Sugar Icons.
Single-icon: The default operation creates a single sugar icon — for instance an activity icon — from the input SVG. By default, the Sugarized icon will be written to a new file named input.sugar.svg, optionally in the output directory specified with -d. By invoking the -o option, the input file will be overwritten in place.
When run, the script attempts to determine the proper hex values for the stroke and fill entities, and asks for confirmation before proceeding. You can preemptively accept this guess with -g, but do so with caution as the proper values cannot be determined with 100% confidence; we strongly recommend against using this in conjunction with the -o option. Should the script be unable to determine the proper entities, you can specify the correct stroke and fill hex values to replace using the -s and -f flags, respectively. Finally, for activity icons, you may find it convenient to apply the recommended default stroke and fill colors (#666666, #FFFFFF) to the output SVG with -c, which will make your icon match the visual style of uninstantiated activities within the UI, as well as the others posted on the wiki.
You may also generate an HTML preview containing a few variations on the icon rendering style, as it may later be seen in Sugar. When the -x flag is passed, a directory named input.preview containing several example SVGs and the HTML file will be created, adjacent your icon output. View this file in Safari or Firefox (other browsers not tested), and observe the tips listed in the preview for validating your icon. At present, HTML previews are only supported for single-icon conversions, and -x will be ignored when passed with the -m flag.
Icon sets: Activity developers may require many icons for placement in toolbars and elsewhere in their activities. To make the process of creating and exporting large numbers of icons easier, this script provides a multiple-export feature. When the -m option is passed, the script will export an entire set of icons from a single input SVG — one for each top level group within it. The resulting files will each contain all of the appropriate stroke and fill entities, and assume the name of the id given to the group that defined it.
In some cases, you may desire to update a single icon, or a subset of the icons defined within a given SVG. To do so, pass a pattern to the script with -p, and only those icons which match the pattern will be exported.
Options
-c Apply default color entities (#666666, #FFFFFF) to output
-d [directory] The preferred output directory
-e Do not insert entities for strokes and fills
-f [hex] Hex value to replace with fill entity
-g Automatically accept guesses for stroke and fill entities
-h Display this help message
-i Insert "isolated stroke" entities
-m Multiple export; export top level groups as separate icons
-o Modify input file in place, overwriting it; overridden by -m
-p [pattern] Only export icons whose name contains pattern
-s [hex] Hex value to replace with stroke entity
-v Verbose
-x Create HTML preview files, for icon validation
=='''<big>SugarIconify class</big>'''==
sugariconify.py it has a class too, so it can be used in any other script easily
==<big>Instantiating SugarIconify</big>==
from sugariconify import SugarIconify
icon = SugarIconify()
==<big>SugarIconify methods</big>==
SugarIconify class has enabled the same functionality of the command line utility, with the following methods to set the desired behavior:
'''set_stroke_color():''' equivalent of -s on command line, it can be a hex value (e.g #FFFFFF) or a rgb percent value such as rgb(32%, 33%, 87%)
from sugariconify import SugarIconify
icon = SugarIconify()
icon.set_stroke_color('#FFFFFF')
icon.set_stroke_color('rgb(55%, 12%, 55%)')
'''set_fill_color():''' equivalent of -f on command line, it can be a hex value (e.g #FFFFFF) or a rgb percent value such as rgb(32%, 33%, 87%)
from sugariconify import SugarIconify
icon = SugarIconify()
icon.set_fill_color('#FFFFFF')
icon.set_fill_color('rgb(55%, 12%, 55%)')
'''set_confirm_guess():''' equivalent of -g on command line, so it can automatically accept guesses for stroke and fill entities, True or False are the only accepted values
from sugariconify import SugarIconify
icon = SugarIconify()
icon.set_confirm_guess(True)
'''set_use_default_colors():''' equivalent of -c on command line, uses default stroke and fill entities (#666666, #FFFFFF) for sugar iconify, True or False are the only accepted values
from sugariconify import SugarIconify
icon = SugarIconify()
icon.set_use_default_colors(True)
'''set_overwrite_input():''' equivalent of -o on command line, overrides input file in place, True or False are the only accepted values
from sugariconify import SugarIconify
icon = SugarIconify()
icon.set_overwrite_input(True)
'''set_output_path():''' equivalent of -d on command line, sets the output path where the iconified file will be placed, string values are accepted
from sugariconify import SugarIconify
icon = SugarIconify()
icon.set_output_path('/home/user/Desktop')
'''set_use_entity():''' equivalent of -e on command line, do not insert entities for strokes and fills, True or False are the only accepted values
from sugariconify import SugarIconify
icon = SugarIconify()
icon.set_use_entity(True)
'''set_verbose():''' equivalent of -v on command line, outputs information messages on console, True or False are the only accepted values
from sugariconify import SugarIconify
icon = SugarIconify()
icon.set_verbose(True)
'''set_pattern():''' equivalent of -p on command line, only export icons whose name contains pattern, string values are accepted.
from sugariconify import SugarIconify
icon = SugarIconify()
icon.set_pattern('pattern')
'''set_multiple():''' equivalent of -m on command line, export top level groups as separate icons, True or False are the only accepted values
from sugariconify import SugarIconify
icon = SugarIconify()
icon.set_multiple(True)
'''set_output_examples():''' equivalent of -x on command line, create HTML preview files, for icon validation, True or False are the only accepted values
from sugariconify import SugarIconify
icon = SugarIconify()
icon.set_output_examples(True)
'''set_use_iso_strokes():''' equivalent of -i on command line, insert "isolated stroke" entities, True or False are the only accepted values
from sugariconify import SugarIconify
icon = SugarIconify()
icon.set_use_iso_strokes(True)
==<big>SugarIconify example</big>==
from sugariconify import SugarIconify
icon = SugarIconify()
icon.set_use_default_colors(True)
icon.iconify('/home/user/Desktop/image.svg')