Is there any way to use imagegrabwindow() with Firefox or Chrome? - php

I'm trying to generate website thumbnails programatically in PHP. To do this, I'm using imagegrabwindow() with a COM object:
$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$browser->Navigate($pre.$URL);
while ($browser->Busy)
{
com_message_pump(4000);
}
$img = imagegrabwindow($handle);
What I'm wondering is if there is any way to do the same thing with Firefox or Chrome? Can I invoke either of them with PHP COM?

You can invoke them with an exec command to the commandline. The Pearl Crescent Page Saver plugin for Firefox will take commandline arguments to save a capture of the page as well.
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.
I tried the Com Object with IE and imagegrabwindow and I just got randomly blacked-out documents. Not finding any help to resolve that situation, scripting a plugin from the commandline seemed the next best viable option.

Related

Script selenium python always detected as bot on flashseats :(

my script always detected why ?!!!!
most of time i use python selenium for scraping website but this time i'am always detected by "https://www.flashseats.com"
Can you help me please!!
here's part of my selenium code , i even try to use different proxies but :( same result,
please propose me a solution either in python or PHP.
chrome_options = webdriver.ChromeOptions()
options = webdriver.ChromeOptions()
options.add_argument('--disable-infobars')
options.add_argument('--disable-extensions')
options.add_argument('--profile-directory=Default')
options.add_argument('--incognito')
options.add_argument('--disable-plugins-discovery')
options.add_argument('--start-maximized')
#_chrome_options = Options()
#_chrome_options.add_argument('disable-infobars')
driver = webdriver.Chrome(r'C:\browser\chromedriver.exe', chrome_options=chrome_options)
time.sleep(10)
driver.get("https://www.flashseats.com/")
I know that might be a late answer, but you can try using Selenium-Profiles or undetected-chromedriver for that.
To answer your question: You're most likely getting detected because of values in javascript like navigator.webdriver, which might be different than in a normal browser.

Scala Lift - Run PHP file from within scala runtime

I'm not entirely sure the wording for the title is correct, but what I'm attempting to do is run and execute PHP files from within the Lift framework.
I'm not after any url queries to a PHP file residing on a server, more interested in somehow getting the PHP runtime working through my Scala/Lift app.
Use case: I have my app packaged into a .war file, I host this via a cloud provider. I upload code snippets to said app which then runs the php file and does whatever necessary.
I've seen various posts regarding Bianca but am hoping to keep this setup light and require only the PHP binary itself and a little code to get it flying.
Thanks in advance, please let me know if you need me to elaborate :)
“Never say never, because limits, like fears, are often just an
illusion.”
― Michael Jordan
What you really need is an open source (GPL), embeddable, full PHP 5 implementation, written entirely in Java!
Caucho's Quercus PHP Java runtime is just that, and it will let you run PHP within a Java app without external libraries or native code.
Below is a Quercus-PHP-in-Java code sample I found in this answer
import javax.script.ScriptEngine;
import com.caucho.quercus.script.QuercusScriptEngineFactory;
QuercusScriptEngineFactory factory = new QuercusScriptEngineFactory();
ScriptEngine engine = factory.getScriptEngine();
String phpCode = "<?php $foo = strlen('abc'); print $foo; return 'yikes'; ?>"; //PHP Code as String
Object o = engine.eval(phpCode);
System.out.println(o);
It should be little effort to convert this code to idiomatic Scala. Obviously, the 'phpCode' variable could be constructed from external PHP file contents etc.
Let us know how you get on ;-)
That's a bit of an odd requirement, but if it's what you need to do, you can use a ProcessBuilder to execute and interact with your PHP script from the command line.

Print multipage PDF on different printer-trays

I am generating a PDF by PHP with FPDF. This works well.
Now what I want:
From a multipage PDF all pages expect the last one have to print with paper from tray1 and the last page from tray2.
Now the Question:
How is this possible? Is this a Acrobat Reader issue? Can it be done with JavaScript in PDF?
It is not possible, as PDFs do not contain any information on the printer trays or other information. It is actually set in the printer instructions through the client's printer driver, who has to provide this information to the client program. If you need this functionality for batch processing, you'd have to leave PHP and get on the client side, e.g. through the Acrobat SDK, in which you can give this information, e.g. on a PostScript printer via the SetPageDevice-function
I use CUPS on an intranet website. I don't specify a tray and my code is ruby, but the principle definitely works.
Here's my code, see if you can adapt it for your scenario
def print(path)
raise ArgumentError, "'#{path}' does not exist" unless File.file?(path)
`lp -s -d printer_name -h 127.0.0.1 -o page-ranges=1-4 -o media=A4,Upper #{path}`
$?.to_i == 0 ? true : false
end
The basic idea is to generate the PDF, save it to disk then call this method to shell out to CUPS. You might need to play with the media option to get it doing what you need. 'Upper' is the tray you're targeting.
Make sure path is sanitised before being passed to this method or you risk opening a security hole.
PHP can send some things to a print server like CUPS, but it can't get something to print on a client's machine save through JavaScript. JavaScript does not have the ability to control the individual's printer settings when being called from a browser. And while there are bindings for embedded PDF's in JS, there is no guarantee that the user will not simply have the file open in a standalone PDF reader (my computer at home is configured this way).
For future readers of this post, if a commercial library is a valid choice then it is possible to do this with Amyuni PDF Creator ActiveX (Delphi, C++, VB, PHP) or with Amyuni PDF Creator .Net (C#, VB.net, etc.) by changing the "PaperBin" property of a page object.
Possible values for this property can be found in the documentation for the DEVMODE structure in MSDN, examples: DMBIN_UPPER - 0x0001, DMBIN_LOWER - 0x0002, DMBIN_AUTO - 0x0007.
The code in C# would look like this:
Amyuni.PDFCreator.IacDocument pdfDoc = new Amyuni.PDFCreator.IacDocument();
using(FileStream fs = File.Open("MyDocument.pdf", FileMode.Open))
{
pdfDoc.Open(fs, "");
}
const int DMBIN_MANUAL = 4;
for( int pageNumber = 1; i <= pdfDoc.PageCount; i++)
{
pdfDoc.GetPage(pageNumber).AttributeByName("PaperBin").Value = DMBIN_MANUAL;
}
pdfDoc.Print("My Laser Printer", False);
For PHP, you will need to use the ActiveX version, and create the document using the ProgID of the ActiveX control:
$pdfdoc = new COM("PDFCreactiveX.PDFCreactiveX");
Note that this approach is about printing to a specific tray using the library, as other answers have mentioned, it is not possible to store this information in the PDF file itself so that it can be used by other applications.
Disclaimer: I currently work for Amyuni Technologies.

How to get a site screenshot quickly using PHP?

I want to create a web directory site, and I need to get these site screenshots. How to get a site screenshot quickly using PHP?
I tried IECAPT,webscreencapture, khtml2png, but they are all slowly. And they all get screenshot one url by one url.
Is IECAPT depends on a ie browser? if it is, why it can not open many ie tags so that work at the same time?
Is there anyone can recommend me a PHP screenshots software using online? according to my above requirements? Thank you.
Your requirements are unrealistic. Your best bet is to integrate with WebKit through something like CutyCapt that doesn't run an actual browser, but just the WebKit rendering engine. You shouldn't have any concurrency issues, but it it isn't going to be fantastic.
These external services are developing fast. Take a look at:
http://immediatenet.com/thumbnail_api.html
it renders thumbnails extremely fast and caches them like the other similar services.
Probably the easiest way is to use an external service. There used to be Alexa Site Thumbnail but it has been discontinued, so you must look for alternatives. For example http://www.pageglimpse.com/ seems to be one.
I have tried CutyCapt, I copied 3 CutyCapt.exe and renamed them. But it also catch the screenshot one by one , not run the 3 processes at one time.
<?php
set_time_limit(0);
$url1 = 'http://www.google.co.uk';
$out1 = '1.jpg';
$path1 = 'CutyCapt1.exe';
$cmd1 = "$path1 -u=$url1 -o=$out1";
//exec($cmd);
system($cmd2);
$url2 = 'http://www.google.com';
$out2 = '2.jpg';
$path2 = 'CutyCapt2.exe';
$height2 = '1200 ';
$cmd2 = "$path2 -u=$url2 -o=$out2";
//exec($cmd);
system($cmd2);
$url3 = 'http://www.google.co.jp';
$out3 = '2.jpg';
$path3 = 'CutyCapt3.exe';
$height3 = '1200 ';
$cmd2 = "$path3 -u=$url3 -o=$out3";
//exec($cmd);
system($cmd3);`
?>
I do not think many thumbnail service site, like pageglimpse.com, they install many browsers on their web servers. What is the technology they use?

Browser performance question

Using an adapted version of jquery.inplace.js for some page creation and use an OBDC connection in the background php file to query for content. Everything works, BUT...
I am surprised that IE6, 7, or 8 are all pretty quick, as is chrome, but firefox seems to take quite a few seconds for exactly the same task, in this case.
This is without firebug, or lots of other add-ons enabled. I am puzzled by what to look for.
It is a fairly simple return of some html content.
What would you try?
A cursory look at the source in the SVN doesn't show anything which I believe firefox would have problems with.
Can you explain exactly what is "slow"? Is it the POST request? Have you tried logging the HTTP Headers sent to the server from both IE and FF?
If it's the javascript itself, try running the profiler in firebug; FF might find a specific function a little "heavy" (for instance, one of the regexes).
Also, FF3.5+ already has String.trim*() methods built-in. The code you're using overwrites those with a custom version, which will be much slower and might even be causing firefox to behave oddly. Try changing the source to the following:
if( String.prototype.trim === undefined ) {
String.prototype.trim = function() {
return this.replace(/^\s+/, '').replace(/\s+$/, '');
};
}
That way the plugin will only add the trim method for older browsers.

Categories