-
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
ebe91e8
commit 1a122ae
Showing
85 changed files
with
30,061 additions
and
234 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
.idea | ||
.idea | ||
node_modules |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,15 @@ | ||
|
||
var gulp = require('gulp'); | ||
var spriter = require('gulp-css-spriter'); | ||
|
||
gulp.task('css', function() { | ||
return gulp.src('./css/recharge.css')//比如recharge.css这个样式里面什么都不用改,是你想要合并的图就要引用这个样式。 很重要 注意(recharge.css)这个是我的项目。别傻到家抄我一样的。 | ||
.pipe(spriter({ | ||
// The path and file name of where we will save the sprite sheet | ||
'spriteSheet': './dist/images/spritesheet.png', //这是雪碧图自动合成的图。 很重要 | ||
// Because we don't know where you will end up saving the CSS file at this point in the pipe, | ||
// we need a litle help identifying where it will be. | ||
'pathToSpriteSheetFromCSS': '../images/spritesheet.png' //这是在css引用的图片路径,很重要 | ||
})) | ||
.pipe(gulp.dest('./dist/css')); //最后生成出来 | ||
}); |
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,122 @@ | ||
let fs = require('fs'); | ||
|
||
let images = require('images'); | ||
|
||
|
||
let option = { | ||
dirPath : '/Users/caozhihui/code/huodong/4399cn/y2017/timeMachine/dev/images/', | ||
outputPath:'/Users/caozhihui/code/huodong/4399cn/y2017/timeMachine/dev/scss/' | ||
}; | ||
|
||
function DealImages(option){ | ||
this.dirPath = option.dirPath; | ||
this.outputPath = option.outputPath; | ||
} | ||
|
||
DealImages.prototype.init = function(){ | ||
this.readAllImages(); | ||
fs.watch(this.dirPath,(eventType,filename)=>{ | ||
if(eventType){ | ||
this.readAllImages(); | ||
} | ||
}); | ||
}; | ||
|
||
DealImages.prototype.readAllImages = function(){ | ||
fs.readdir(this.dirPath,(err,data)=>{ | ||
if(err){ | ||
console.log(err); | ||
return false; | ||
} | ||
|
||
this.callback('writeStylesheet',data); | ||
}); | ||
}; | ||
|
||
DealImages.prototype.filterImages = function(data){ | ||
|
||
let formatAry = ['bmp','png','jpeg','gif'] | ||
|
||
let newAry = []; | ||
|
||
data.forEach((item,index)=>{ | ||
|
||
let suffix = item.split('.')[1]; | ||
|
||
if(formatAry.indexOf(suffix) != -1){ // 如果 judge 里面有 说明是图片 | ||
newAry.push(item); | ||
} | ||
}); | ||
|
||
return newAry; | ||
|
||
}; | ||
|
||
DealImages.prototype.getSize = function(filePath){ | ||
|
||
let size = images(filePath); | ||
|
||
return { | ||
width : size.width(), | ||
height : size.height() | ||
} | ||
}; | ||
|
||
DealImages.prototype.template = function(w,h,fileName,fileNameAll){ | ||
return `@mixin ${fileName}(){ | ||
width:${w}rem/$base; | ||
height:${h}rem/$base; | ||
background:url(../images/${fileNameAll}) no-repeat; | ||
background-size:100% auto; | ||
} | ||
`; | ||
} | ||
|
||
DealImages.prototype.writeStylesheet = function(data){ | ||
|
||
let imagesAry = this.filterImages(data); | ||
|
||
let template = ``; | ||
|
||
imagesAry.map((item,index)=>{ | ||
|
||
let fileName = item.split('.')[0]; | ||
|
||
let filePath = this.dirPath + item; | ||
|
||
let size = this.getSize(filePath); | ||
|
||
template += this.template(size.width,size.height,fileName,item); | ||
|
||
}); | ||
|
||
let outputPath = this.outputPath + 'imagesStylesheet.scss'; | ||
|
||
fs.writeFile(outputPath,template,(err)=>{ | ||
if(err){ | ||
console.log(err); | ||
return err; | ||
} | ||
}); | ||
}; | ||
|
||
|
||
DealImages.prototype.callback = function(strategy,data){ | ||
this.strategies(strategy,data) || console.log(strategy + '您回调的策略对象不存在~'); | ||
}; | ||
|
||
DealImages.prototype.strategies = function (strategy,data){ | ||
|
||
if(this[strategy]){ | ||
|
||
this[strategy](data); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
let deal = new DealImages(option); | ||
deal.init(); | ||
|
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,15 @@ | ||
{ | ||
"name": "imageinfo", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "caozhihui", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"gulp-css-spriter": "^0.4.0", | ||
"images": "^3.0.0" | ||
} | ||
} |
Oops, something went wrong.