php 抓取网页生成图片( 2016年04月18日17:51:21张大鹏这篇文章 )

优采云 发布时间: 2022-02-05 06:13

  php 抓取网页生成图片(

2016年04月18日17:51:21张大鹏这篇文章

)

  使用PHP+JavaScript将HTML页面转为图片的示例分享

  更新时间:2016-04-18 17:51:21 作者:张大鹏

  本篇文章主要介绍使用PHP+JavaScript将HTML元素转化为图片的实例分享。结果截图只能体现替换后的字体,不能说将静态页面转为图片可以加快加载速度。只是对这种做法比较感兴趣的朋友可以参考XD

  1.准备要素

  1)替换字体的js文件

  js代码:

<p>

function com_stewartspeak_replacement() {

/*

Dynamic Heading Generator

By Stewart Rosenberger

http://www.stewartspeak.com/headings/

This script searches through a web page for specific or general elements

and replaces them with dynamically generated images, in conjunction with

a server-side script.

*/

replaceSelector("h1","dynatext/heading.php",true);//前两个参数需要修改

var testURL = "dynatext/loading.gif" ;//修改为对应的图片路径

var doNotPrintImages = false;

var printerCSS = "replacement-print.css";

var hideFlicker = false;

var hideFlickerCSS = "replacement-screen.css";

var hideFlickerTimeout = 100;//这里可以做相应的修改

/* ---------------------------------------------------------------------------

For basic usage, you should not need to edit anything below this comment.

If you need to further customize this script's abilities, make sure

you're familiar with Javascript. And grab a soda or something.

*/

var items;

var imageLoaded = false;

var documentLoaded = false;

function replaceSelector(selector,url,wordwrap)

{

if(typeof items == "undefined")

items = new Array();

items[items.length] = {selector: selector, url: url, wordwrap: wordwrap};

}

if(hideFlicker)

{

document.write('');

window.flickerCheck = function()

{

if(!imageLoaded)

setStyleSheetState('hide-flicker',false);

};

setTimeout('window.flickerCheck();',hideFlickerTimeout)

}

if(doNotPrintImages)

document.write('');

var test = new Image();

test.onload = function() { imageLoaded = true; if(documentLoaded) replacement(); };

test.src = testURL + "?date=" + (new Date()).getTime();

addLoadHandler(function(){ documentLoaded = true; if(imageLoaded) replacement(); });

function documentLoad()

{

documentLoaded = true;

if(imageLoaded)

replacement();

}

function replacement()

{

for(var i=0;i 0) for(var j=0;j

0 个评论

要回复文章请先登录注册


官方客服QQ群

微信人工客服

QQ人工客服


线