Skip to content

Commit f1fba36

Browse files
更改VT中处理图像的工具。(node-images换为pngjs+image-size)
1 parent 39e378d commit f1fba36

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

examples-test/base/commonTools.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var fs = require('fs');
2-
var path = require('path');
2+
var PNG = require('pngjs').PNG;
33
var getPixels = require("get-pixels");
4-
var images = require('images');
4+
var size = require('image-size');
55
var n = 0; //截图次数
66

77
var commonTools = ({
@@ -42,12 +42,14 @@ var commonTools = ({
4242
browser.pause(5000);
4343
browser.saveScreenshot(screenShotPath, function () {
4444
console.log('Screenshot has been saved , now start to get StdTile from Screenshot');
45-
var totalWidth = images(screenShotPath).width();
46-
var totalHeight = images(screenShotPath).height();
47-
var offX = (totalWidth - width) / 2 + offsetX;
48-
var offY = (totalHeight - height) / 2 - offsetY;
49-
commonTools.getTileFromScreenshot(screenShotPath, offX, offY, width, height, tileTestPath);
50-
console.log('get StdTile completed');
45+
size(screenShotPath, function (err, dimensions) {
46+
var totalWidth = dimensions.width;
47+
var totalHeight = dimensions.height;
48+
var offX = (totalWidth - width) / 2 + offsetX;
49+
var offY = (totalHeight - height) / 2 - offsetY;
50+
commonTools.getTileFromScreenshot(screenShotPath, offX, offY, width, height, tileTestPath);
51+
console.log('get StdTile completed');
52+
});
5153
});
5254
browser.pause(2000, function () {
5355
commonTools.deleteFolders('./examples-test/temp');
@@ -77,12 +79,14 @@ var commonTools = ({
7779
browser.pause(5000);
7880
browser.saveScreenshot(screenShotPath, function () {
7981
console.log('start to get test tile');
80-
var totalWidth = images(screenShotPath).width();
81-
var totalHeight = images(screenShotPath).height();
82-
var offX = (totalWidth - width) / 2 + offsetX;
83-
var offY = (totalHeight - height) / 2 - offsetY;
84-
commonTools.getTileFromScreenshot(screenShotPath, offX, offY, width, height, tileTestPath);
85-
console.log('get test tile completed');
82+
size(screenShotPath, function (err, dimensions) {
83+
var totalWidth = dimensions.width;
84+
var totalHeight = dimensions.height;
85+
var offX = (totalWidth - width) / 2 + offsetX;
86+
var offY = (totalHeight - height) / 2 - offsetY;
87+
commonTools.getTileFromScreenshot(screenShotPath, offX, offY, width, height, tileTestPath);
88+
console.log('get test tile completed');
89+
});
8690
});
8791
browser.pause(5000, function () {
8892
console.log('start to compare test tile with standard tile');
@@ -95,7 +99,11 @@ var commonTools = ({
9599
* offX, offY: Offset relative to the top-left corner
96100
* */
97101
getTileFromScreenshot: function (sourceImagePath, offX, offY, width, height, tilePath) {
98-
images(images(sourceImagePath), offX, offY, width, height).save(tilePath);
102+
var dst = new PNG({width: width, height: height});
103+
fs.createReadStream(sourceImagePath).pipe(new PNG()).on('parsed', function () {
104+
this.bitblt(dst, offX, offY, width, height, 0, 0);
105+
dst.pack().pipe(fs.createWriteStream(tilePath));
106+
});
99107
},
100108

101109
/*

0 commit comments

Comments
 (0)