I am currently making a website where I simply want users to be able to screenshot a webpage and then download the image. So what I need help with is: how do I screenshot a webpage using PHP then save the image on my server.
I have read a few other tutorials on how to screenshot a page, but I can't get it to work.
I am using a Linux server (Debian 7.0).
You can use grabz.it
Take Website Screenshots with PHP
Get your free Application Key and Secret.
Download the free PHP Demo and Library and try it out.
Then use it like this:
include("GrabzItClient.class.php");
$grabzIt = new GrabzItClient("APPLICATION KEY", "APPLICATION SECRET");
$grabzIt->SetImageOptions("http://www.google.com");
$grabzIt->SaveTo("google.jpg");
If you don't want to depend on 3rd parties, you can use phantomjs, i.e.:
phantomjs responsive-screenshot.js http://google.com
Notes:
1- Download responsive-screenshot.js. Check the source code for available options.
2- You can install phantomjs by cloning the github repo:
git clone https://github.com/ariya/phantomjs.git
I recently published a project that gives PHP access to a browser. Get it here: https://github.com/merlinthemagic/MTS
Like previous answers the project relies on PhantomJS.
After downloading and setup you would simply use the following code:
$myUrl = "http://www.google.com";
$windowObj = \MTS\Factories::getDevices()->getLocalHost()->getBrowser('phantomjs')->getNewWindow($myUrl);
//now do a screenshot, valid formats are png, jpeg, gif.
$imageData = $windowObj->screenshot("png");
file_put_contents("/path/to/your/file.png", $imageData);
Related
I'm trying to create a web application using PHP (Laravel 5.8) where user can past link of any video found on the Internet (like Youtube, Dailymotion ... etc), then cut the video.
Cutting the video the video both in front-end and back-end is easy to do, I'm using PHP-FFMPeg to do it in server side.
My problem is that I couldn't find a solution to open a remote video from my PHP script, i.e if user past this link "https://www.dailymotion.com/video/x6rh0" I would open it then make a clip.
This my code :
$ffmpeg = FFMpeg\FFMpeg::create();
$url = "https://www.dailymotion.com/video/x6rh0";
$video = $ffmpeg->open($url);
$clip = $video->clip(FFMpeg\Coordinate\TimeCode::fromSeconds(30), FFMpeg\Coordinate\TimeCode::fromSeconds(15));
$clip->save(new FFMpeg\Format\Video\X264('libmp3lame', 'libx264'), public_path().'/videos/video2.avi');
I'm using PHP Laravel framework.
Please, how can I open a video from URL using PHP-FFMpeg, this is my question.
I'm trying to download files from a Google Drive link from Google server to my web server, to avoid the 100 max size in PHP POST.
<?php
$link = $_POST["linkToUpload"];
$upload = file_put_contents("uploads/test".rand().".txt", fopen($link, 'r'));
header("Location: index.php");
?>
Inserting a normal link like http://example.com/text.txt it works fine. The problem comes linking google drive https://drive.google.com/uc?authuser=0&id=000&export=download. This is a direct link from Google Drive, but it doesn't work. So I tried to insert the link that I obtained downloading the file locally https://doc-08-bo-docs.googleusercontent.com/docs/securesc/000/000/000/000/000/000?e=download and it's still not working. Do you think Google is trying to avoid the server-to-server copies? Or there is another method to do it?
If you want to fetch files with your own application you should use the API (Application Programming Interface) to get these.
Have a look at the file download documentation for Google Drive
Example download snippet in PHP:
$fileId = '0BwwA4oUTeiV1UVNwOHItT0xfa2M';
$response = $driveService->files->get($fileId, array(
'alt' => 'media'));
$content = $response->getBody()->getContents();
Question 1
I am trying to set up server side for Apple passes so they can be updated. I am currently generating signed zipped passes, which also register to update my tables, with device tokens /id Etc.
The passes do not update with the new passes I generate (Same serial, auth token - different message/image)
In console I'm getting this error (fault):
BOM could not extract archive : Couldn't read PKZIP signature
Received invalid pass data (The pass cannot be read because it isn\U2019t valid
I am using https://github.com/tschoffelen/PHP-PKPass
Along with storing data & passes, and the webserviceurl php page on my server.
Any one got an idea on this?
Question 2
I am also getting an error (fault) in console:
Setting display properties with screenSize=(375, 667) scale=2
Not sure why, or if this even matters?
Fixed!
I created my own version of a generator like the github link.
That fixed the issue.
The problem is in the way ZIP (pkpass) files are generated. I've looked at the code and it's using PHP's ZipArchive. Though the ZIP files generated can be extracted both on Windows and Linux without errors, Apple server is more picky.
I've tried PclZip as well, and it has the same problem.
The solution is to use system() call to zip files using the command-line zip command. The ZIP file generated this way is accepted by Apple.
I'm trying to generate a PHP client for my Google Cloud Endpoints API using the Google APIs Client Generator but it just creates an empty directory instead.
The command I'm using looks like:
generate_library --language=php --language_variant=stable --output_dir=/path/php-client --input=/path/myApi-v1.json
It seems to work when I change the language to csharp and java. I turned on the verbose flag and don't see any errors, only tracing messages like:
DEBUG:codegen:Create: myMethod, parent=update
DEBUG:codegen:Schema.Create: updateRequestContent => MyMessage
DEBUG:codegen:DataTypeFromJson: add MyMessage to cache
Searching around I see someone at the AppEngine sub Reddit posted a similar issue with no response.
I used another approach:
downloaded the zip from
https://github.com/google/apis-client-generator
Extracted the zip file in a directory (i named it client-generator)
Executed the generate.sh script available in the extracted files.
/path/client-generator/generate.sh --input=/path/rest.json --language=php --output_dir=/path/output
The APICLassName.php file is generated
I tried again and changed the --language_variant argument from stable to 1.1.4 and it now works fine.
I have a rather complicated scenario that I have never really had to deal with before. I am creating a website that will be hosted on a web-server without PHP support. But I need to call a PHP script that returns a Flash Slideshow. Is there any way that I can do this? Here is the bit of PHP code that I need to call to return the Flash Slideshow.
<?php
//include slideshow.php to access the Insert_Slideshow function
include "http://mywebsite/slideshow.php";
//insert the slideshow.swf flash file into the web page
//tell slideshow.swf to get the slideshow's data from sample.php created in the first step
//set the slideshow's width to 320 pixels and the height to 240
echo Insert_Slideshow ( "http://mywebsite/slideshow.swf", "http://mywebsite/sample.php", 600, 500 );
?>
To run PHP on your server (not another server) you will definitely need to install a PHP processor.
However since you have a hard-coded URL in there, it looks as though the PHP code is just some kind of utility function for inserting a flash movie.
Run the PHP code on your local computer (for example) and see what HTML it generates, and if it always generates that same HTML, why not just copy it and use that in your website.
You could have the PHP script execute on a PHP enabled webserver somewhere else and include it in an iframe on the page without PHP support. That would be quite ugly, tho.
Although you obviously can't run PHP on a server that doesn't have it, if your slideshow doesn't change frequently perhaps you could run your PHP script on another machine, capture the output, then upload that to your web host.
This is not possible. If you need to call a PHP script, its obvious that you need PHP installed on the web server.