NSprite

A yii based sprite generator extension

  • 所有者: steve-obrien/NSprite
  • 平台:
  • 许可证:
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

NSPrite is an extension for the Yii Framework.
It can be found here: http://www.yiiframework.com/extension/nsprite/

The NSprite Yii extension aims to help solve the problem of generating sprites for your application.

There are many great icon libraries that are ubiquitous on the web, - famfamfam - fugue Each of these have thousands of icons, a typical project uses a handfull of these.

This class allows you to dump the individual image files you want into a folder or set of folders. The class then generates the sprite from all the images in these folder(s) and publishes the sprite.png plus the generated sprite.css file into the assets folder.

Requirements

  • Tested with Yii 1.8. relies on the CAssetManager and the CFileHelper so it should work on Yii 1.0 and above.
  • GD php library
  • Tested on PHP 5.2 and 5.3, may also work on previous versions

Installation

1 Download the sprite.zip package
2 Extract it and place the sprite folder into your extensions folder
3 The assets folder must be writable.
4 Add the sprite component to you Yii app's confirguration

Usage

In you main config

'components'=>array(
    'sprite'=>array(
    'class'=>'ext.sprite.NSprite',
    // if you remove the imageFolderPsth setting it will use the icon folder within   
    // the sprite package (ext.sprite.icons)
    'imageFolderPath'=>array(
        Yii::getPathOfAlias('modules.project.images'),
        'path/to/another/folder'
    )
),

Then somewhere in your application you just have to register the css file.

Yii::app()->sprite->registerSpriteCss();

The css classes generated follow a convention. Each class will have a parent class (defaults to ".sprite", or ".icon") that set the background image to the generated sprite. Each icon/image in your set of image folders (set by "imageFolderPath") will have a class name equivalent to their relative file path within the imageFolderPath.

For example an image folder containing:

fam/add.png
myicons/groovy.png
fugue/pencil.png

Will generate the following css classes:

.sprite{background-image:url(sprite.png);}
.icon{display:inline;overflow:hidden;padding-left:18px;background-repeat:no-repeat;background-image:url(sprite.png);}
.fam-add{background-position:-16px 0px;width:6px;height:16px;}
.myicons-groovy{background-position:-16px -16px;width:16px;height:16px;}
.fugue-pencil{background-position:-16px -32px;width:16px;height:16px;}

And can be used like:

<div class="sprite fam-add"></div> <!-- use on block elements -->
<span class="icon fam-add"></span> <!-- use with 16px x 16px image inline -->

The .sprite class is the general purpose class that adds the sprite as a background image. Nothing more. The .icon class is a helper for sprite icons typically for famfamfam and fugue 16 x 16 pixel images for use with images 16px by 16px, the sprite generator does support all sizes of images but you may have to add css to suite your situation.

Obviously you can override the .sprite and .icon classes (and change their name) to provide the css trickery required for your application.

主要指标

概览
名称与所有者steve-obrien/NSprite
主编程语言PHP
编程语言PHP (语言数: 1)
平台
许可证
所有者活动
创建于2011-07-26 09:29:15
推送于2012-11-24 11:32:36
最后一次提交2012-11-24 11:32:30
发布数0
用户参与
星数4
关注者数1
派生数0
提交数4
已启用问题?
问题数0
打开的问题数0
拉请求数0
打开的拉请求数0
关闭的拉请求数0
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?