Skip to content

Commit

Permalink
Make images centered inside their padded box.
Browse files Browse the repository at this point in the history
  • Loading branch information
selaux committed Jun 5, 2015
1 parent b652c9f commit 6ff85eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/layout/packed.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ module.exports = function generateLayout(images, options, callback) {

packed = binPack(images);
images = _.map(packed.items, function (image) {
var paddingOffset = options.padding / 2;

return _.extend({}, image.item, {
x: image.x,
y: image.y,
x: image.x + paddingOffset,
y: image.y + paddingOffset,
width: image.width - options.padding,
height: image.height - options.padding
});
Expand Down
6 changes: 3 additions & 3 deletions test/specs/layout/packed.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ describe('Layout/Packed', function () {
width: 50,
height: 50,
images: [
_({ x: 0, y: 0 }).extend(images[0]),
_({ x: 30, y: 0 }).extend(images[1]),
_({ x: 0, y: 30 }).extend(images[2])
_({ x: 5, y: 5 }).extend(images[0]),
_({ x: 35, y: 5 }).extend(images[1]),
_({ x: 5, y: 35 }).extend(images[2])
]
});
expect(layout.images[0]).not.to.equal(images[0]);
Expand Down

0 comments on commit 6ff85eb

Please sign in to comment.