PHP怎样抓屏?
Windows下用PHP做网页截图
在Apache的服务属性里,“登录”选项卡中选中“允许服务与桌面交换”就行了!
?
<?php $browser = new COM("InternetExplorer.Application"); $handle = $browser->HWND; $browser->Visible = true; $browser->Width = 500; $browser->Height = 500; $browser->Navigate("http://www.un.org"); /* Still working? */ while ($browser->Busy) { com_message_pump(4000); } $im = imagegrabwindow($handle, 0); $browser->Quit(); imagepng($im, "iesnap.png"); ?>
?运行这段代码的时候服务器上会弹出一个IE窗口并自动打开指定的网站,截屏后窗口自动关闭,相当傻瓜!
?
?
?
?
?
Linux下用PHP做网页截图
上alexa 时,总能看到alexa 显示被查询网站的首页截图,这个截图是怎么实现的呢。
通过察看页面内容,发现原来是通过调用amazon的服务程序
获得的。
http://ast.amazonaws.com/Xino/?Action=Redirect&Service=AlexaSiteThumbnail&Url=baidu.com&
AWSAccessKeyId=1FVZ0JNEJDA5TK457CR2&Signature=tz4xyqDNcSf8A1v%2BpDo4todvM9c%3D&
Size=Small&Timestamp=2008-03-04T06%3A04%3A47.422Z&
DefaultImage=http%3A%2F%2Fclient.alexa.com%2Fcommon%2Fimages%2Fnoimages.gif
如果想在自己的网站中做出这种效果,完全可以在amazon申请一个ID获得这样的调用接口来实现。
但是,这样怎么符合探究精神?所以,经过一番翻箱倒柜,找到下面的方法来自己实现网站的首页截图。
实现网站首页页面缩略图制作。
步骤:
1. 启动一个页面抓取工具,抓取选定的网站首页;
2.存储抓取的页面截图到服务器
上;
3.按照需要显示的大小处理抓取的页面截图;
4.把结果展现给用户
。
综上所述,其实关键是在于需要有一个稳定的抓取工具,经过在网上寻找,找到下面几个工具。
在windows环境下,可以考虑这个工具软件来抓页面截图:
IECapt.exe
在linux环境下,可以考虑这个工具软件来抓页面截图:
HTML2Image
获得抓取工具之后,就可以采用任何一种服务器语言
编写程序,调用这个抓取工具,然后把抓取结果返回给用户。
下面是利用IECapt.exe并结合PHP抓取网站截图的例子。
在Windows/Apache2.2/Php5.2.5 下运行通过。
参考资料:
1.http://www.zubrag.com/scripts/website-thumbnail-generator.php
2.http://www.guangmingsoft.net/htmlsnapshot/html2image.htm
官方url:http://www.guangmingsoft.net/htmlsnapshot/html2image.htm
Linux
kernel- 2.2.14及以上: 安装必需lib及相关软件
yum install -y glibc gtk+ fontconfig??cairo libpixman pango pango-devel
下载html2image
wget http://www.guangmingsoft.net/htmlsnapshot/html2image.i386.tar.gz
tar xvzf html2image.i386.tar.gz
CD html2image
设置LD_LIBRARY_PATH路径
export LD_LIBRARY_PATH=./
mkdir /usr/X11R6/lib
ln - s /usr/share/X11 /usr/X11R6/lib/X11
运行Xvfb
./Xvfb :1 -screen 0 640x480x24 -nolisten tcp -audit 4 -auth X1.cfg & export DISPLAY=:1
生成图片
./html2image www.google.com
a.jpg
可忽略的错误:
error opening security policy file /usr/X11R6/lib/X11/xserver/SecurityPolicy
Could not init font path element /usr/X11R6/lib/X11/fonts/TTF/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/Speedo/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/Type1/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/CID/, removing from list!
生成1024x768 格式 容量
jpg 871K
gif 4.12M
png 1.13M

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

WebStorm Mac version
Useful JavaScript development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Notepad++7.3.1
Easy-to-use and free code editor
