l.s.s.SpriteUtil : class documentation

Part of lp.services.spriteutils View In Hierarchy

No class docstring
Method __init__ Initialize with the specified css template file.
Method combineImages Copy all the sprites into a single PIL image.
Method savePNG Save the PIL image object to disk.
Method savePositioning Save the positions of sprites in the combined image.
Method loadPositioning Load file with the positions of sprites in the combined image.
Method saveConvertedCSS Generate new css from the template and the positioning info.
Method _loadCSSTemplate See __init__.
Method _getSpriteImagePath Convert the url path to a filesystem path.
Method _parseCommentParameters Parse parameters out of javascript comments.
def __init__(self, css_template_file, group_name, url_prefix_substitutions=None, margin=150):
Initialize with the specified css template file.

:param css_template_file: (str) Name of the file containing
    css rules with a background-image style that needs to be
    combined into the sprite file, a comment allowing sprites to
    be grouped into different image files, and a
    background-repeat style if necessary. Currently, "repeat-y"
    is not supported since the file is combined vertically, so
    repeat-y would show the entire combined image file.

    Example css template:
        edit-icon {
            background-image: url(../edit.png)
            /* sprite-ref: group1 */
        }
        blue-bar {
            background-image: url(../blue-bar.png)
            /* sprite-ref: group1 */
            background-repeat: repeat-x
        }

:param group_name: (str) Only add sprites to the
    combined image file whose sprite-ref comment in the
    css template match this group-name.

:param url_prefix_substitutions: (dict) The css template
    will contain references to image files by their url
    path, but the filesystem path relative to the css
    template is needed.

:param margin: (int) The number of pixels between each sprite.
    Be aware that Firefox will ignore extremely large images,
    for example 64x34000 pixels.

If the css_template_file has been modified, a new
css file using an existing combined image and positioning
file can be generated using:
    sprite_util = SpriteUtil(...)
    sprite_util.loadPositioning(...)
    sprite_util.saveConvertedCSS(...)

If a new image file needs to be added to the combined image
and the positioning file, they can be regenerated with:
    sprite_util = SpriteUtil(...)
    sprite_util.combineImages(...)
    sprite_util.savePNG(...)
    sprite_util.savePositioning(...)

If the image file is regenerated any time the css file is
regenerated, then the step for saving and loading the positioning
information could be removed. For example:
    sprite_util = SpriteUtil(...)
    sprite_util.combineImages(...)
    sprite_util.savePNG(...)
    sprite_util.saveConvertedCSS(...)
def _loadCSSTemplate(self, css_template_file, group_name, url_prefix_substitutions=None):
See __init__.
def _getSpriteImagePath(self, rule, url_prefix_substitutions=None):
Convert the url path to a filesystem path.
def _parseCommentParameters(self, parameter_string):
Parse parameters out of javascript comments.

Currently only used for the group name specified by "sprite-ref".

def combineImages(self, css_dir):
Copy all the sprites into a single PIL image.
def savePNG(self, filename):
Save the PIL image object to disk.
def savePositioning(self, filename):
Save the positions of sprites in the combined image.

This allows the final css to be generated after making changes to the css template without recreating the combined image file.

def loadPositioning(self, filename):
Load file with the positions of sprites in the combined image.
def saveConvertedCSS(self, css_file, combined_image_url_path):
Generate new css from the template and the positioning info.

Example css template:
    background-image: url(../edit.png); /* sprite-ref: group1 */
Example css output:
    background-image: url(combined_image_url_path)
    background-position: 0px 2344px
API Documentation for Launchpad, generated by pydoctor at 2022-06-16 00:00:12.