-
Notifications
You must be signed in to change notification settings - Fork 5
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
李银池
committed
May 24, 2020
1 parent
cdef641
commit b6d07fd
Showing
42 changed files
with
1,619 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.DS_Store | ||
node_modules/ | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
.history | ||
/back-end | ||
# Editor directories and files | ||
.idea | ||
.vscode | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln |
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,50 @@ | ||
const cheerio = require('cheerio'); | ||
var fs = require('fs'); | ||
var request = require('request'); | ||
var chalk = require('chalk'); | ||
var program = require('commander'); | ||
var CurrentFilePath=__dirname; | ||
var FilePath; | ||
program | ||
.version('1.0.0') | ||
.option('-p, --FilePath [type]', '下载后图片文件存放位置', "image") | ||
.parse(process.argv); | ||
// 判断是否有入参 | ||
console.log(chalk.green.bold('params:')); | ||
if (program.FilePath === undefined) { | ||
console.log(chalk.green.bold('no FilePath'));; | ||
} else if (program.FilePath === true) { | ||
console.log(chalk.green.bold('add FilePath'));; | ||
} else { | ||
console.log(chalk.green.bold(`add FilePath type ${chalk.blue.bold(program.FilePath)}`)); | ||
FilePath = program.FilePath; | ||
} | ||
|
||
fs.readFile(`${CurrentFilePath}/index.html`,"utf-8",function(err,data){ | ||
if(err) { | ||
console.log("index.html loading is failed :"+err); | ||
} | ||
else{ | ||
var $ = cheerio.load(data); | ||
var tr_list = $('table tr'); | ||
tr_list.each((index, item) => { | ||
var imgName = $(item).find('td').eq(0).text(); | ||
var imgUrl = $(item).find('td').eq(1).text(); | ||
var writeStream = fs.createWriteStream(`${CurrentFilePath}/${FilePath}/${imgName}${imgUrl.substring(imgUrl.lastIndexOf('.'))}`); | ||
var readStream = request(imgUrl); | ||
readStream.pipe(writeStream); | ||
readStream.on('end', function() { | ||
console.log(`${chalk.blue.bold(imgName)} ${chalk.blue.bold("Download Finish")} ${chalk.green.bold("Finish")}`); | ||
}); | ||
readStream.on('error', function() { | ||
console.log(chalk.red.bold("Error:" + err)) | ||
}); | ||
writeStream.on("finish", function() { | ||
console.log(`${chalk.blue.bold(imgName)} ${chalk.blue.bold("Save")} ${chalk.green.bold("Success")}`); | ||
writeStream.end(); | ||
}); | ||
}); | ||
} | ||
|
||
}); | ||
|
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,22 @@ | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
</head> | ||
|
||
<body> | ||
<table border="1"> | ||
<tr> | ||
<td>图片1</td> | ||
<td>https://www.baidu.com/img/superlogo_c4d7df0a003d3db9b65e9ef0fe6da1ec.png</td> | ||
</tr> | ||
<tr> | ||
<td>图片2</td> | ||
<td>https://dss1.bdstatic.com/kvoZeXSm1A5BphGlnYG/skin/1.jpg</td> | ||
</tr> | ||
<tr> | ||
<td>图片3</td> | ||
<td>https://dss1.bdstatic.com/kvoZeXSm1A5BphGlnYG/skin/2.jpg</td> | ||
</tr> | ||
</table> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
var sharp = require("sharp"); | ||
var chalk = require("chalk"); | ||
var program = require('commander'); | ||
var imageFormat; | ||
var width; | ||
var height; | ||
var inputImage; | ||
var outputImage; | ||
program | ||
.version('1.0.0') | ||
.option('-f, --imageFormat [type]', '生成图片的格式,例如:jpg、jpeg、png、bmp、gif、webp、tiff、svg等', "jpg") | ||
.option('-w, --width [type]', '生成图片的宽(单位:像素)', 200) | ||
.option('-e, --height [type]', '生成图片的 图片存放位置', 200) | ||
.option('-i, --inputImage [type]', '原始图片存放位置', "Made/image/format.jpg") | ||
.option('-o, --outputImage [type]', '生成图片后,图片所存放的置', "Made/output/format") | ||
.parse(process.argv); | ||
|
||
console.log(chalk.green.bold('params:')); | ||
if (program.imageFormat === undefined) { | ||
console.log(chalk.green.bold('no imageFormat'));; | ||
} else if (program.imageFormat === true) { | ||
console.log(chalk.green.bold('add imageFormat'));; | ||
} else { | ||
console.log(chalk.green.bold(`add imageFormat type ${chalk.blue.bold(program.imageFormat)}`)); | ||
imageFormat = program.imageFormat; | ||
} | ||
if (program.width === undefined) { | ||
console.log(chalk.green.bold('no width'));; | ||
} else if (program.width === true) { | ||
console.log(chalk.green.bold('add width'));; | ||
} else { | ||
console.log(chalk.green.bold(`add width type ${chalk.blue.bold(program.width)}`)); | ||
width = program.width; | ||
} | ||
if (program.height === undefined) { | ||
console.log(chalk.green.bold('no height'));; | ||
} else if (program.height === true) { | ||
console.log(chalk.green.bold('add height'));; | ||
} else { | ||
console.log(chalk.green.bold(`add height type ${chalk.blue.bold(program.height)}`)); | ||
height = program.height; | ||
} | ||
if (program.inputImage === undefined) { | ||
console.log(chalk.green.bold('no inputImage'));; | ||
} else if (program.inputImage === true) { | ||
console.log(chalk.green.bold('add inputImage'));; | ||
} else { | ||
console.log(chalk.green.bold(`add inputImage type ${chalk.blue.bold(program.inputImage)}`)); | ||
inputImage = program.inputImage; | ||
} | ||
if (program.outputImage === undefined) { | ||
console.log(chalk.green.bold('no outputImage'));; | ||
} else if (program.outputImage === true) { | ||
console.log(chalk.green.bold('add outputImage'));; | ||
} else { | ||
console.log(chalk.green.bold(`add outputImage type ${chalk.blue.bold(program.outputImage)}`)); | ||
outputImage = program.outputImage; | ||
} | ||
|
||
|
||
sharp(inputImage).resize(Number(width), Number(height)).toFile(`${outputImage}.${imageFormat}`, function (err) { | ||
if (err) { | ||
console.error(chalk.red.bold(err)); | ||
} | ||
console.log(chalk.green.bold("Success")+" 执行完毕"); | ||
console.log(chalk.green.bold("Please view file dir")+" Made/output"); | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
var fs = require("fs"); | ||
var chalk = require("chalk"); | ||
var program = require('commander'); | ||
var newFileName; | ||
var newFileFormat; | ||
var newFilePath; | ||
program | ||
.version('1.0.0') | ||
.option('-n, --newFileName [type]', '图片名称', "Image") | ||
.option('-f, --newFileFormat [type]', '图片格式', "bmp") | ||
.option('-p, --newFilePath [type]', '图片存放位置', "image") | ||
.parse(process.argv); | ||
console.log(chalk.green.bold('params:')); | ||
if (program.newFileName === undefined) { | ||
console.log(chalk.green.bold('no newFileName'));; | ||
} else if (program.newFileName === true) { | ||
console.log(chalk.green.bold('add newFileName'));; | ||
} else { | ||
console.log(chalk.green.bold(`add newFileName type ${chalk.blue.bold(program.newFileName)}`)); | ||
newFileName = program.newFileName; | ||
} | ||
if (program.newFileFormat === undefined) { | ||
console.log(chalk.green.bold('no newFileFormat'));; | ||
} else if (program.newFileFormat === true) { | ||
console.log(chalk.green.bold('add newFileFormat'));; | ||
} else { | ||
console.log(chalk.green.bold(`add newFileFormat type ${chalk.blue.bold(program.newFileFormat)}`)); | ||
newFileFormat = program.newFileFormat; | ||
} | ||
if (program.newFilePath === undefined) { | ||
console.log(chalk.green.bold('no newFilePath'));; | ||
} else if (program.newFileName === true) { | ||
console.log(chalk.green.bold('add newFilePath'));; | ||
} else { | ||
console.log(chalk.green.bold(`add newFilePath type ${chalk.blue.bold(program.newFilePath)}`)); | ||
newFilePath = program.newFilePath; | ||
} | ||
var path = `${__dirname}/${newFilePath}`; | ||
fs.readdir(path, function (err, files) { | ||
if (err) { | ||
return console.error(chalk.red(err)); | ||
} | ||
var n = 0; | ||
files.forEach(function (file) { | ||
n++; | ||
if (file.replace('^.*\.(jpg|gif|png|bmp)$i')) { | ||
var oldfilePath = path + `/${file}`; | ||
var newFilePath = `${path}/${newFileName}${n}.${newFileFormat}`; | ||
console.log(`${chalk.green('Batch Rename Success ')}${chalk.green.blue(newFileName)}${chalk.yellow.bold(n)}.${chalk.blue.bold(newFileFormat)}`); | ||
fs.rename(oldfilePath, newFilePath, function (error) { | ||
if (error) { | ||
console.error(`${chalk.red(err)}`); | ||
} | ||
|
||
}) | ||
} | ||
}); | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
var sharp = require("sharp"); | ||
var chalk = require("chalk"); | ||
var program = require('commander'); | ||
var inputImage; | ||
var width; | ||
var height; | ||
var outputImage;program | ||
.version('1.0.0') | ||
.option('-i, --inputImage [type]', '被修改图片存放位置', "Resize/image/resize.jpg") | ||
.option('-w, --width [type]', '宽(单位:像素)', 200) | ||
.option('-e, --height [type]', '图片存放位置', 200) | ||
.option('-o, --outputImage [type]', '被修改后的图片存放位置', "Resize/output/resize.jpg") | ||
.parse(process.argv); | ||
console.log(chalk.green.bold('params:')); | ||
if (program.inputImage === undefined) { | ||
console.log(chalk.green.bold('no inputImage'));; | ||
} else if (program.inputImage === true) { | ||
console.log(chalk.green.bold('add inputImage'));; | ||
} else { | ||
console.log(chalk.green.bold(`add inputImage type ${chalk.blue.bold(program.inputImage)}`)); | ||
inputImage = program.inputImage; | ||
} | ||
if (program.width === undefined) { | ||
console.log(chalk.green.bold('no width'));; | ||
} else if (program.width === true) { | ||
console.log(chalk.green.bold('add width'));; | ||
} else { | ||
console.log(chalk.green.bold(`add width type ${chalk.blue.bold(program.width)}`)); | ||
width = program.width; | ||
} | ||
if (program.height === undefined) { | ||
console.log(chalk.green.bold('no height'));; | ||
} else if (program.newFileName === true) { | ||
console.log(chalk.green.bold('add height'));; | ||
} else { | ||
console.log(chalk.green.bold(`add height type ${chalk.blue.bold(program.height)}`)); | ||
height = program.height; | ||
} | ||
if (program.outputImage === undefined) { | ||
console.log(chalk.green.bold('no outputImage'));; | ||
} else if (program.newFileName === true) { | ||
console.log(chalk.green.bold('add outputImage'));; | ||
} else { | ||
console.log(chalk.green.bold(`add outputImage type ${chalk.blue.bold(program.outputImage)}`)); | ||
outputImage = program.outputImage; | ||
}sharp(inputImage).resize(Number(width), Number(height)).toFile(outputImage, function (err) { | ||
if (err) { | ||
console.error(chalk.red.bold(err)); | ||
} | ||
console.log(chalk.green.bold("Success")+" 执行完毕"); | ||
}) | ||
|
||
|
||
|
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.