-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a122ae
commit bb6b8ac
Showing
42 changed files
with
409 additions
and
1,932 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
const fs = require('fs'); | ||
const images = require('images'); | ||
|
||
|
||
/* | ||
* 原理 将两张图片合成一张 | ||
* | ||
* */ | ||
let option = { | ||
dirPath : './images/', | ||
outputPath:'./images/', | ||
outputName : 'sprites.png', | ||
spacing : 10, | ||
}; | ||
|
||
function Sprite(option) { | ||
|
||
this.option = option; | ||
|
||
this.init(); | ||
} | ||
|
||
|
||
Sprite.prototype.init = function(){ | ||
|
||
this.imagesAry = this.filterImages(this.getAllImagesAry(this.option.dirPath)); // 获取图片并过滤不是图片的资源 | ||
|
||
this.createSprites(); | ||
|
||
}; | ||
|
||
Sprite.prototype.createSprites = function(){ | ||
|
||
this.createFirstSprites(); // 创建第一张雪碧图 | ||
|
||
|
||
}; | ||
|
||
Sprite.prototype.synthetic = function(){ //将两张图片合成一张 | ||
|
||
}; | ||
|
||
Sprite.prototype.createFirstSprites = function(){ //创建第一张雪碧图 | ||
|
||
let firstImage = this.imagesAry.pop(); | ||
|
||
let imagePath = this.getImagePath(firstImage); | ||
|
||
let {w,h} = this.getImageSize(imagePath); | ||
|
||
let outputPath = this.option.outputPath + this.option.outputName; | ||
console.log(imagePath); | ||
images(w + this.option.spacing,h + this.option.spacing) | ||
.draw(images(imagePath),0,0) | ||
.save(outputPath) | ||
|
||
|
||
}; | ||
|
||
Sprite.prototype.createEmptyImage = function(w,h){ //创建空白图层 | ||
|
||
let path = this.option.outputPath + this.option.outputName; | ||
|
||
images(w,h).save(path); | ||
|
||
}; | ||
|
||
Sprite.prototype.getImagePath = function(imageName){ | ||
/* 这个 要加路径判断 判断最后路径 有没有 / */ | ||
|
||
return this.option.dirPath + imageName; | ||
}; | ||
|
||
Sprite.prototype.getImageSize = function(dirPath){ | ||
|
||
let size = images(dirPath); | ||
|
||
return {w:size.width(),h:size.height()}; | ||
|
||
}; | ||
|
||
Sprite.prototype.getAllImagesAry = function(dirPath){ | ||
|
||
let result = []; | ||
|
||
try { | ||
result = fs.readdirSync(dirPath); | ||
}catch (e){ | ||
console.log(e); | ||
result = []; | ||
} | ||
|
||
return result; | ||
}; | ||
|
||
Sprite.prototype.filterImages = function(imagesAry){ | ||
|
||
let formatAry = ['bmp','png','jpeg','gif']; | ||
|
||
let newAry = []; | ||
|
||
imagesAry.forEach((item,index)=>{ | ||
|
||
let suffix = item.split('.')[1]; | ||
|
||
if(formatAry.indexOf(suffix) != -1){ // 如果 judge 里面有 说明是图片 | ||
newAry.push(item); | ||
} | ||
}); | ||
|
||
return newAry; | ||
|
||
}; | ||
|
||
|
||
|
||
var sprite = new Sprite(option); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const fs = require('fs'); | ||
const images = require('images'); | ||
|
||
images(1000,1000) | ||
.draw(images("./images/logo.png"), 80, 80) | ||
.save('outer.png'); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const fs = require('fs'); | ||
const gm = require('gm'); | ||
const path = require('path'); | ||
var imageMagick = gm.subClass({ imageMagick: true }); | ||
|
||
gm('done.png') | ||
.size(function (err, size) { | ||
console.log(arguments); | ||
if (!err) | ||
console.log(size.width > size.height ? 'wider' : 'taller than you'); | ||
}); |