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?
Related
I couldn't find any better answer to this online, even the document of liquidsoap isn't helpful. What I want to happen is to grab the current song title and artist being played in my streaming server(icecast). I found in some forum that they were able to do it but they didn't explain it how, here's the liquidsoap script that they used:
def apply_metadata(m) =
title = m["title"]
artist = m["artist"]
album = m["album"]
[("artist","#{artist}"),("title","#{album} - #{title}")]
end
centovacast.callback_autodj := fun(s) -> map_metadata(apply_metadata,s)
This script i believe is also for centova and autodj only. While I do not use those technology (I'm using Ubuntu 16.04, Icecast2, Liquisoap, PHP, HTML5/CSS),
is this possible to do using the tools I'm currently using?
I used to use websockets to get the metadata but I found it frustrating that it was always out of sync.
The only way to solve it is to have the metadata encoded into the stream so you receive it at the same time as the audio.
I did a bit of digging around to find out how the icecast servers do it and put together a service worker script which adds the necessary header to your request to obtain a stream including metadata and then extracts it for you.
The code is here and there is a simple demo here
I hope this helps, anyway, I think that here, weserWEB, has already somehow said something similar.
If you're using Icecast version 2.4.4 you can consume the metadata from this endpoint: (if not, consider downloading that version)
http://<your-ipaddress-or-domain>:<port_number>/status-json.xsl
Just put that in any browser and you will get a JSON with the name of the song and title you are streaming, you have to configure properly your streaming client first, of course.
Then you can get the metadata from that endpoint without problems in your PHP. You can use CURL to get the JSON data, liquidsoap not necessary.
I'm not sure why you are dragging the source client into this.
A proper stream sent to an Icecast mountpoint will have metadata for currently playing audio.
This has been pointed out elsewhere. Icecast since 2.4.1 provides a proper JSON metadata export.
Querying JSON from within a website is very much a solved problem and considered an exercise for the inclined reader.
Why don't you grab this at icecast directly?
PHP:
function get_icecast_info($server_ip, $server_port, $admin_user, $admin_password) {
$index = #file_get_contents("http://".$admin_user.":".$admin_password."#".$server_ip.":".$server_port."/admin/stats.xml");
if($index) {
$xml = new DOMDocument(); if(!$xml->loadXML($index)) return false; $arr = array(); $listItem = $xml->getElementsByTagName("source");
foreach($listItem as $element) {
if($element->childNodes->length) {
foreach($element->childNodes as $i){ $arr[$element->getAttribute("mount")][$i->nodeName] = $i->nodeValue; }
}
}
return $arr;
} return false;
}
And this is the output (array):
$arr = get_icecast_info($ice_host, $ice_aport, $ice_user, $ice_pass);
Hi,
I want to get the screenshot of several pages and display them on my website. As of now, I am using the method below:
<?php
$site = $screenurl;
$image = file_get_contents("https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=$site&screenshot=true");
$image = json_decode($image, true);
$image = $image['screenshot']['data'];
$image = str_replace(array('_','-'),array('/','+'),$image);
echo "<img src=\"data:image/jpeg;base64,".$image."\" alt=\"\">";
?>
but with 10 or more images per page, this method takes FOREVER to load them all or it wont even load them at all because it times out. I would like to know a more effective, optimized and faster way to do this.
Thank you.
Not sure if this is exactly what you're looking for, but PHP's built-in (PHP >= 5.2.2) imagegrabscreen function is capable of returning an image resource containing a screenshot of the whole screen. It is sort of picky, though, from what I understand (never used it myself), requiring it to be run on a Windows system and "allow Apache service to interact with the desktop". These documentation pages could be helpful:
imagegrabscreen Function
imagegrabwindow Function
How can I change the site url in an image source url to a new site url, something like this:
Original Image: http://domain.com/theme/wp-content/uploads/2014/12/image.jpg
After Replace: http://new-domain.com/new-theme/wp-content/uploads/2014/12/image.jpg
How can I do this using PHP?
I make it by using str_replace
http://php.net/str_replace
$old_src = 'http://domain.com/theme/wp-content/uploads/2014/12/image.jpg';
$old_url = 'http://domain.com/theme/';
$new_url = 'http://new-domain.com/new-theme/';
$new_src = str_replace($old_url, $new_url, $old_src ).'<br/>';
echo $new_src;
The easiest way to make this change is at a database level.
I do this kind of thing all the time when I deploy a site and I need to change the staging domain (staging.test.com) to the live domain (test.com). Generally, Wordpress generally uses the WP_SITEURL set in wp-config.php to determine asset paths but this is not the case for images.
I use the Search and Replace for Wordpress databases script and it's pretty solid, just replace:
http://domain.com/theme/
with
http://new-domain.com/new-theme/
and you should be good to go...
Alternatively, if you're not moving a site then you can change specific instances in the database - for this I'd recommend using a tool like Navicat (for OSX) as this can perform search/replace operations on specific tables.
I have an automated archive of several (media) websites' frontpage, written in php. Specifically, I am copying the html in the <body> tag twice a day, I have a copy of all their css and js files, so I can recreate the frontpage from any point in the past. Now, I came to a problem with one of those websites, as they load the main slider content (most important news) with an ajax call. I would like this ajax call to be executed before I parse the data, not just a blank div. By looking around, I found out they use a wordpress plugin named lof-jslidernews2, but I can't find the specific ajax call to see the url and make curl request. Any ideas how to achieve this?
The website: http://fokus.mk/
My code (had to parse manually like this, because of some problems with DomDocument and not-valid html):
// ...
if($html = file_get_contents ($row['page_url'])) {
$content = strstr($html, '<body');
$content = str_before($content, '</body>') . '</body>';
$filename = date('YmdHis') . $row['page_name'];
if($success = file_put_contents ('app/webroot/files/' . $filename, $content)) {
// ....
** There is nothing illegal about my project, I am not stealing content, just freezing frontpages for later comparison. I have consulted a lawyer about this. :)
I don't know why, but the guy that actually solved my problem deleted his answer. So, here it is:
He suggested using an emulator, specifically Mink. It was easy to install (using composer) and did the job on the first try. Awesome library.
Mink is an open source browser controller/emulator for web applications, written in PHP 5.3.
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.