css绝对定位手机差异

Continuing from last night...

从昨晚开始...

First, two twitter responses pointed to even more readily-available options for comparing screenshots. One is Wraith from BBC engineers which supports Firefox/Gecko (via SlimerJS) in addition to PhantomJS. The other is the almost-ready siteeffect.io which is based on http://dalekjs.com/ which seems to support all the browsers!

首先,两个Twitter响应指出了用于比较屏幕截图的更容易获得的选项。 BBC工程师的Wraith之一就是PhantomJS,它还支持Firefox / Gecko(通过SlimerJS)。 另一个是基于http://dalekjs.com/的几乎可以使用的siteeffect.io ,它似乎支持所有浏览器!

Anyway, I thought I should add Firefox support to my brave little script via SlimerJS and also do what I hinted at the end of the previous post - do the image diff in nodejs-land instead of ImageMagick.

无论如何,我认为我应该通过SlimerJS将Firefox支持添加到我勇敢的小脚本中,并且也按照我在上一篇文章末尾的提示进行操作-在nodejs-land而不是ImageMagick中进行图像比较。

SlimerJS (SlimerJS)

It's pretty cool, just like PhantomJS. I didn't manage to install it using regular package managers (like brew) but luckily you can just download it standalone and run from anywhere. So I shoved in ~/Downloads/slimerjs

就像PhantomJS一样,它非常酷。 我没有使用常规的软件包管理器(例如brew)安装它,但是幸运的是,您可以独立下载它并在任何地方运行。 所以我推到~/Downloads/slimerjs

A quick script to add Mozilla/Gecko support to the url2png functionality:

将Mozilla / Gecko支持添加到url2png功能的快速脚本:

var system = require('system');
var url = system.args[1];
var png = system.args[2];
var page = require('webpage').create();
page.viewportSize = { width: 800, height: 600 };
page
.open(url)
.then(function() {
page.render(png);
phantom.exit();
});

Testing:

测试:

$ ~/Downloads/slimerjs/slimerjs url2png-moz.js http://google.com goo.png

This makes a screenshot of Google's homepage into goo.png

goo.png Google主页的屏幕截图变成goo.png

Node.js中的图像差异 (Image diff in nodejs)

I found this library called pngparse (hmm, no GD in NodeJS?) which does exactly what I need - reads a png and gives width/height and array of RGBA pixel values, just like image data you'd get from HTML canvas.

我发现了这个名为pngparse的库(嗯, NodeJS中没有GD?),它确实满足我的需要-读取png并提供宽度/高度和RGBA像素值数组,就像从HTML canvas获得的图像数据一样。

So here's a function that simply returns true if the two images are the same:

所以这是一个函数,如果两个图像相同,则仅返回true

function sameImage(image_a, image_b, cb) {
var pngparse = require('pngparse');
pngparse.parseFile(image_a, function(err, a) {
if (err) {
console.log('Where the first file? ' + image_a + ' is not it.');
process.exit(2);
}
pngparse.parseFile(image_b, function(err, b) {
if (err) {
console.log('Where the second file? ' + image_b + ' is not it.');
process.exit(3);
}
// easy stuffs first
if (a.data.length !== b.data.length) {
return cb(false);
}
// loop over pixels, but
// skip 4th thingie (alpha) as these images should not be transparent
for (var i = 0, len = a.data.length; i < len; i += 4) {
if (a.data[i]     !== b.data[i] ||
a.data[i + 1] !== b.data[i + 1] ||
a.data[i + 2] !== b.data[i + 2]) {
return cb(false);
}
}
return cb(true);
});
});
}

The benefits of doing this in Node instead of ImageMagick is just speed. (Disclaimer: Not that I tested but...). There's no separate cmd like process to exec(), there's no weird metrics to calculate, just give up as soon as just one of the R, G or B channels is different between the two images. Skip Alpha. Or even give up as soon as one of the images has more data, meaning different geometry, meaning definitely not the same image.

在Node而不是ImageMagick中执行此操作的好处仅仅是速度。 (免责声明:不是我测试过,而是...)。 exec()没有单独的cmd like流程,没有可计算的怪异指标,只要两个图像之间的R,G或B通道之一不同就放弃。 跳过Alpha。 甚至在其中一张图像具有更多数据时就放弃,这意味着不同的几何形状,这意味着绝对不是同一幅图像。

最终结果 (End result)

So with a bit of reshuffling and adding support for both webkit and gecko and changing the image diff logic, here's what I ended up with:

因此,经过一些改组并增加了对webkit和gecko的支持并更改了图像差异逻辑,这就是我最终得到的结果:

var exec = require('child_process').exec;
var read = require('fs').readFileSync;
var sprintf = require('sprintf').sprintf;
var write = require('fs').writeFileSync;
var tmp = process.cwd() + '/tmp/';
var html = read('source/zen.html', 'utf8');
var before = html.replace('{{{FILE}}}', '../source/before.css');
var after = html.replace('{{{FILE}}}', '../source/after.css');
write('tmp/before.html', before);
write('tmp/after.html',  after);
var phantoms = [
{name: 'webkit', path: 'phantomjs'},
{name: 'moz', path: '~/Downloads/slimerjs/slimerjs'},
];
phantoms.forEach(function(tool) {
var before = 'tmp/before-' + tool.name + '.png';
var after =  'tmp/after-'  + tool.name + '.png';
var giff =   'tmp/giff-'   + tool.name + '.gif';
var before_cmd = sprintf('%s url2png-%s.js "%s" %s',
tool.path,
tool.name,
'file://'+ tmp + 'before.html',
before);
var after_cmd = sprintf('%s url2png-%s.js "%s" %s',
tool.path,
tool.name,
'file://'+ tmp + 'after.html',
after);
var giff_cmd = sprintf('convert -delay 50 -loop 0 %s %s %s', before, after, giff);
exec(before_cmd, function() {
exec(after_cmd, function() {
sameImage(before, after, function(same) {
if (same) {
console.log('all good in ' + tool.name);
} else {
exec(giff_cmd);
console.log('Bad, bad! Failure in ' +
tool.name + '. See stuff in ' + tmp +
', e.g. ' + giff + ' to help you debug');
process.exit(1);
}
});
});
});
});

You can browse all the files right here: http://www.phpied.com/files/diffcss2/

您可以在这里浏览所有文件: http : //www.phpied.com/files/diffcss2/

下一个? (Next?)

1. I'm pretty sure there's gotta be a way to do animated GIFs with NodeJS so dump ImageMacick completely 2. What about the elephant in the room - IE6-11?

1.我很确定肯定有一种方法可以使用NodeJS制作GIF动画,因此完全转储ImageMacick 2. 2.房间里的大象-IE6-11呢?

Tell your friends about this post on Facebook and Twitter

在Facebook和Twitter上告诉您的朋友有关此帖子的信息

翻译自: https://www.phpied.com/css-diffs-2/

css绝对定位手机差异

css绝对定位手机差异_CSS差异#2相关推荐

  1. 系统较低的Android手机文字自动换行差异 CSS调整

    系统较低的Android手机文字自动换行差异 文字没沾满宽度就会自动换行包括文字,英文 1.宽度固定: 2.word-break:break-all;(英文一个完整词不会自动换行,不要此段CSS 如图 ...

  2. HTML浏览器解析位置错误,各浏览器对CSS错误解析规则的差异及CSS hack.pdf

    各浏览器对各浏览器对CSS错误解析规则的差异错误解析规则的差异及及CSS hack 标签标签 :_ , * , -moz-..., -webkit-... , !important, hack, 兼容 ...

  3. css怎么使元素绝对定位有过度效果_小猿圈web前端讲解div+css绝对定位和相对定位...

    最近很多网友问我绝对定位和相对定位怎么区分,怎么使用?绝对是什么地方的绝对,相对又是相对于什么地方而言的呢?那他们又有什么样的特性,可以做出什么样的效果呢?关于两者之间又有什么样的技巧呢?下面小猿圈w ...

  4. php如何使用遮罩,CSS绝对定位实现窗口遮罩功能:2019年1月15日作业

    CSS绝对定位实现窗口遮罩功能: 这是HTML代码部分 实例 html> 绝对定位之遮罩 用户登录窗口 用户名: 密码: 登录 运行实例 » 点击 "运行实例" 按钮查看在线 ...

  5. java 补丁差异_差异和补丁简介

    java 补丁差异 如果您曾经使用分布式开发模型开发大型代码库,那么您可能已经听说过有人说" Sue刚发送了补丁"或" Rajiv正在检查差异"之类的事情. 也 ...

  6. css绝对定位如何居中?css绝对定位居中的四种实现方法-web前端教程

    在网页进行css布局时居中是经常需要用到的,其中就有css绝对定位居中,那么,css绝对定位如何实现居中?今天的这篇文章将给大家来介绍关于css绝对定位居中的实现方法. css绝对定位居中的实现方法有 ...

  7. html绝对定位自适应不同分辨率,(css)绝对定位如何在不同分辨率下的电脑正常显示位置?...

    关于网友提出的" (css)绝对定位如何在不同分辨率下的电脑正常显示位置?"问题疑问,本网通过在网上对" (css)绝对定位如何在不同分辨率下的电脑正常显示位置?&quo ...

  8. CSS @media - 手机和平板适配

    tip: 1.css默认手机样式,平板在此基础上修改数值: 2.以500px作为两者区分 1.手机css h3{height: 4.96rem;padding-top: 1.51rem;font-si ...

  9. CSS - 禁止手机移动端网页缩放(meta)

    前言 您一定不希望手机网页被缩放,本文将提供给您简易的解决方案. 解决方案 注意:该方法并不能 "完全" 控制(浏览器有自己的缩放)其缩放,如果想要完全控制则需要使用 JS 加码了 ...

最新文章

  1. (zz)ubuntu 9.04 下无线破解
  2. 如何使用Fescar保证Dubbo微服务间的一致性
  3. debian安vs_debian下使用vs code
  4. Java黑皮书课后题第2章:2.9(物理:加速度)平均加速度定义为速度的变化量除以这个变化所用的时间,编写程序,提示用户输入以米/秒为单位的起始速度v0,以米/秒为单位的终止速度v1,显示平均加速度
  5. Spring事务隔离级别,事务传播行为
  6. javaScript学习之路(1)词法结构
  7. 免授权版傻瓜式建站系统
  8. openstack 功能_2016年OpenStack的新功能:看一下Newton版本
  9. 佩奇,是你吗?曝新款AirPods外观酷似吹风机
  10. web测试内容及工具经典总结
  11. java_web学习(六) request对象中的get和post差异
  12. c#设计的简单登录界面
  13. 搜狗输入法纯净_最新PC端搜狗输入法,无广告弹窗纯净版
  14. CentOS查看文件夹大小
  15. spring cloud - 概述
  16. 42u的机柜供服务器安装位置,一个42U标准服务器机柜能放多少台服务器
  17. series转换成dataframe
  18. python教程app下载地址_Python爬取APP下载链接的实现方法
  19. Unity Shader 之 正方形图片四角圆角的简单实现(不用遮罩Mask)
  20. 4、selenium3的安装

热门文章

  1. android设置夜间模式切换,android主题切换(简单的白/夜间模式的切换)
  2. IP首部校验和计算与程序设计
  3. 常用性能压测工具实战总结
  4. 播客php,谈谈国内三大PHP播客系统代码试用体验和建议
  5. 转:愈正视自己的冲突,愈能获得内心的自由
  6. 几步轻松学会图纸测量
  7. HTML5,敢问路在何方
  8. 用txt文本显示图片
  9. 多用户通讯系统(网络编程,多线程,IO流,面向对象)
  10. C++中常见的几种输入字符串的方法