Skip to content

Commit c1f3ee2

Browse files
committed
fixes #17
1 parent b30aea2 commit c1f3ee2

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

lib/css-sprite.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module.exports = function (opt) {
6363
var canvas = new Canvas(layerInfo.width, layerInfo.height);
6464
var ctx = canvas.getContext('2d');
6565
lodash.each(layerInfo.items, function (sprite, index) {
66-
ctx.drawImage(sprite.meta.img, sprite.x, sprite.y, sprite.width, sprite.height);
66+
ctx.drawImage(sprite.meta.img, sprite.x + opt.margin, sprite.y + opt.margin, sprite.width - opt.margin * 2, sprite.height - opt.margin * 2);
6767
});
6868
return canvas;
6969
}
@@ -82,10 +82,10 @@ module.exports = function (opt) {
8282
lodash.each(layerInfo.items, function (sprite, index) {
8383
sprites.push({
8484
'name': sprite.meta.name,
85-
'x': sprite.x,
86-
'y': sprite.y,
87-
'width': sprite.width,
88-
'height': sprite.height,
85+
'x': sprite.x + opt.margin,
86+
'y': sprite.y + opt.margin,
87+
'width': sprite.width - opt.margin * 2,
88+
'height': sprite.height - opt.margin * 2,
8989
'total_width': layerInfo.width,
9090
'total_height': layerInfo.height,
9191
'image': sprite.meta.image
@@ -100,7 +100,8 @@ module.exports = function (opt) {
100100
total_width: sprite.canvas.width,
101101
total_height: sprite.canvas.height
102102
});
103-
lodash(layerInfo.items).each(function (sprite, i) {
103+
104+
lodash(sprites).each(function (sprite, i) {
104105
sprites[i].x = Math.floor(sprite.x / 2);
105106
sprites[i].y = Math.floor(sprite.y / 2);
106107
sprites[i].width = Math.floor(sprite.width / 2);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "css-sprite",
3-
"version": "0.8.0-beta1",
3+
"version": "0.8.0-beta2",
44
"description": "css sprite generator",
55
"license": "MIT",
66
"repository": {

0 commit comments

Comments
 (0)