PHP imagegrabwindow GD 库仅返回黑色图像
我希望有人可以帮助我和其他许多人解决这个问题...
我想使用 php 的 imagegrabwindow 函数部分和 GD 库创建一个网站的屏幕截图
在花了一整天的时间实现代码后,我终于可以捕获图像并将其保存到文件中,但是图像是黑色的,而不是我期望的图像...
经过进一步调查,我了解到图像是黑色的原因之一是因为 apache 没有打开与桌面交互 - 因此会创建黑色图像 - 问题是我没有将 Apache 作为服务器运行,我正在运行 IIS 6...
服务中是否有一个设置允许我与桌面交互?如果有人可以指出我正确的方向吗?
<?php
$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$browser->Fullscreen = true;
$browser->Navigate("http://localhost/site/advertise/index.asp");
/* Still working? */
while ($browser->Busy) {
com_message_pump(4000);
}
$im = imagegrabwindow($handle, 0);
imagepng($im, "iesnap6.jpg");
$browser->Quit();
?>
感谢下面的答案,我已将 imagepng 更改为 imagejpeg - 但仍然得到黑色图像...
imagejpeg($im, "iesnap7.jpg");
任何帮助将不胜感激!
谢谢,
我已将代码修改为:社交成瘾者仍然没有成功,图像以黑色显示!
<?php
header('Content-type: image/jpeg');
$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$browser->Navigate("http://localhost/advertise/index.asp");
/* Still working? */
while ($browser->Busy) {
com_message_pump(4000);
}
$im = imagegrabwindow($handle, 0);
$browser->Quit();
imagejpeg($im," file2.jpg");
imagedestroy($im);
?>
Social Addict - 我已经添加了标题 - 我还不断更改 file1.jpg 名称以确保它没有使用黑色缓存图像...仍然不走运!
I am hoping that there is someone that can help me and many others with this problem...
I want to create a screenshot of a website using the imagegrabwindow function part of php and the GD library
After spending the whole day implementing the code I finally can capture the image and save it to a file, but the image is black and not the image that I expected...
On further investigation I have learned that one of the reasons why the image is black is because apache is not turned on to interact with the desktop - and because of this creates a black image - The issue is I am not running Apache as a server I am running IIS 6...
Is there a setting in Services that I should allow to interact with the desktop? and if there is can somebody point me in the right direction?
<?php
$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$browser->Fullscreen = true;
$browser->Navigate("http://localhost/site/advertise/index.asp");
/* Still working? */
while ($browser->Busy) {
com_message_pump(4000);
}
$im = imagegrabwindow($handle, 0);
imagepng($im, "iesnap6.jpg");
$browser->Quit();
?>
Thanks to the answers below I have changed imagepng to imagejpeg - But still get a black image...
imagejpeg($im, "iesnap7.jpg");
Any help would be much appreciated!
Thanks
I have ammended the code to this: Social Addict still no success with the image showing up in Black!
<?php
header('Content-type: image/jpeg');
$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$browser->Navigate("http://localhost/advertise/index.asp");
/* Still working? */
while ($browser->Busy) {
com_message_pump(4000);
}
$im = imagegrabwindow($handle, 0);
$browser->Quit();
imagejpeg($im," file2.jpg");
imagedestroy($im);
?>
Social Addict - I have added the header - I am also constantly changing the file1.jpg name to make sure it is not using a black cached images... still no luck!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我以前遇到过这个问题,通常是当您尝试加载或将图像转换为不正确的类型时引起的,
我认为这可能与此行有关,
您将其另存为 png 并将其命名为 jpg 。
正如您所说,尝试以下操作 jpeg
尝试
设置在 imagejpeg 调用之前输入标头:
然后直接从浏览器访问脚本并查看是否有效?
这也是 PHP.NET 的另一个已知问题
I've had this problem before and is often caused when you try and load or convert an image to an incorrect type
I think it may be something to do with this line
You are saving it as a png and naming it as a jpg here.
Try the following as you have stated you want jpeg
instead
Try setting the header type before the imagejpeg call:
then accessing the script from the browser directly and see if that works?
Also this is another known issue from PHP.NET
是否允许 IIS 和 WWW Publishingservice 与桌面交互?
我的电脑 ->管理->服务-> [IIS 和 WWWPub...] ->登录选项卡 ->允许与桌面交互
Are the IIS and WWW Publishingservice allowed to interact with the desktop?
My computer -> manage -> services -> [IIS and WWWPub...] -> LoginTab -> Allow to interact with desktop
我遇到了同样的问题,尝试将颜色分辨率更改为 32 位,然后重试。
i had the same problem, try change color resolution to 32 bits and try again.
我在使用 imagegrabwindow() 时遇到问题。最终,在找不到解决问题的帮助后,我决定看看是否可以编写现有的页面捕获插件或扩展的脚本。我发现 Firefox 的 Pearl Crescent Page Saver 可以通过命令行编写脚本。
http://pearlcrescent.com/products/pagesaver/doc/#commandline
基本信息版本给你的灵活性不如他们的付费版本,但基本版本满足了我的需求。它也可能适用于非 Windows 系统,但我还没有尝试过。
I was having problems with imagegrabwindow(). Eventually, after finding no help with the problem, I decided to see if I could script an existing page-capture plugin or extention. I found that Pearl Crescent Page Saver for Firefox is scriptable from the commandline.
http://pearlcrescent.com/products/pagesaver/doc/#commandline
The Basic version gives you less flexibility than their paid version, but the basic version met my needs. It may also work on non-Windows systems, but I haven't tried it.
我不久前就发现了这个问题:主要问题是我的专用服务器没有安装 32 位显卡。这导致图像显示黑色...
我更新了服务器硬件并安装了 32 位显卡,现在它可以正常工作。
I have figured out the issue a while back: The main problem were that my dedicated server did not have a 32 bit Graphics Card Installed. This caused the images to display black...
I updated my server hardware and installed a 32 bit graphics card and now it is working with no issues.
我刚刚找到了一个可能最有帮助的答案。摘自 PHP.net 上的评论者:
http://www.php.net/manual/en/function.imagegrabscreen.php
如果没有此选项,则 Apache 无法与您的计算机桌面通信并返回一个空白图像。
I just found an answer that probably will help most. Taken from a commentor on PHP.net:
http://www.php.net/manual/en/function.imagegrabscreen.php
If you don't have this, then Apache can't communicate with your computer desktop and returns a blank image.
“Content-Type”中的“t”必须大写。
之前:
之后:
现在对我有用..
The 't' in 'Content-Type' needs to be capital.
Before:
After:
It works for me now..