screen
screen copied to clipboard
Implement on Laravel
I know this might sound funny but I'm trying to call the library on Laravel from within a controller and can't seem to get it right. This is my setup:
app/Http/Controllers/indexController.php
is where I plan on using the screen capturing.
app/Http/Lib/Screen/
is where I have the library.
I tried a bunch of use
options and nothing seemed to work.
How should I call the library?
Thanks in advance!
install the library via Composer and call it as any other
You're right. Bad habit I do sometimes.
Though I have another weird issue.
This is my code:
$url = 'https://github.com';
$screenCapture = new Capture($url);
$screenCapture->setWidth(1200);
$screenCapture->setHeight(800);
$screenCapture->setImageType('png');
$fileLocation = '/screen/';
$screenCapture->save($fileLocation); // Will automatically determine the extension type
echo $screenCapture->getImageLocation();
The save function is throwing this error:
PhantomJsException in Capture.php line 259:
'C:\xampp\htdocs\projectfolder' is not recognized as an internal or external command,
operable program or batch file.
What's the problem? The fileLocation
path?
I tried a few different options and they all threw the same error.
Any help would be really appreciated.
Thanks
strange.
try setting the phantomjs dir with
$screenCapture->binPath = '/path/to/bin/dir/';
no idea why this error appears, maybe @MASNathan knows
We might be getting somewhere.
I added this:
$screenCapture->binPath = '/vendor/microweber/screen/bin/';
And now the error changed to PhantomJsException in Capture.php line 259: The system cannot find the path specified.
Try this:
Add the following to your composer.json
file. The binaries will be downloaded in your vendor/bin
directory. For more info regarding this process, view the PhantonJS installer documentation.
{
//---
"scripts": {
"post-install-cmd": [
"PhantomInstaller\\Installer::installPhantomJS"
],
"post-update-cmd": [
"PhantomInstaller\\Installer::installPhantomJS"
]
}
//---
}
And then run
$ composer require jakoch/phantomjs-installer microweber/screen
Didn't work. It's something to do with the way it reads the path.
When adding: $screenCapture->binPath = '/vendor/microweber/screen/bin/';
The error is: The system cannot find the path specified.
Just for the heck of it, I added this: $screenCapture->binPath = 'vendor/microweber/screen/bin/';
(left out the first slash) and it threw: 'vendor' is not recognized as an internal or external command, operable program or batch file.
When I add the actual full path on my computer it also throws an error.
Any idea why this is happening? Such a shame, I really want to use this on my project...
@skittery I realise some years have passed since you posted this comment so you've probably moved on, but for the sake of posterity.
It looks like you're specifying a relative path from your project root to the bin directory whereas I believe you need to specify an absolute path. In a Laravel context you can do this with the base_path()
helper. Just pass the relative path string as the argument into that function and it will automatically prepend the absolute path to the project directory.
$screenCapture->binPath = base_path('vendor/microweber/screen/bin/');
Hi @AndrewFeeney Thanks a lot for replying to this. I actually still do need this functionality so I wanted to give it another shot. I installed a brand new Laravel instalation (6.0.1) and it worked perfectly.
I built the functionality in a controller using use Screen\Capture;
and it actually worked.
I don't exactly know what the problem was last time, but I didn't have to use your method.
Thanks for the good work!
BTW - small question - Is there anyway I can take a screenshot, say of 1920 width and 1080 height, but when I clip it to be say 500 it will shrink it without cropping?
Thanks!
@skittery Yes, I noticed shortly after I posted my comment that the default path should work. That said, I've started using a different package by Spatie: https://github.com/spatie/browsershot as it relies on Puppeteer and headless Chrome instead of the now deprecated phantomjs.
Regarding your question, it sounds like you are trying to resize the image after capture, preserving the aspect ratio. I can't see any methods on this package for that. You could use another library to resize the image after the fact. Spatie's package does offer this functionality by exposing their image library: https://github.com/spatie/browsershot#manipulating-the-image
Wow, Spatie seems excellent. Thanks a lot for that!
On Tue, Sep 10, 2019 at 11:39 PM Andrew Feeney [email protected] wrote:
@skittery https://github.com/skittery Yes, I noticed shortly after I posted my comment that the default path should work. That said, I've started using a different package by Spatie: https://github.com/spatie/browsershot as it relies on Puppeteer and headless Chrome instead of the now deprecated phantomjs.
Regarding your question, it sounds like you are trying to resize the image after capture, preserving the aspect ratio. I can't see any methods on this package for that. You could use another library to resize the image after the fact. Spatie's package does offer this functionality by exposing their image library: https://github.com/spatie/browsershot#manipulating-the-image
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/microweber/screen/issues/95?email_source=notifications&email_token=ADA4A3HDND6P6EQPYJRBHDTQJAAXTA5CNFSM4EBSQVXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6MNKVA#issuecomment-530109780, or mute the thread https://github.com/notifications/unsubscribe-auth/ADA4A3HN2WQZ42DP5YERCUDQJAAXTANCNFSM4EBSQVXA .
-- [image: photo] Avi Klein OK Digital [email protected] | http://okdigital.me http://www.linkedin.com/in/kleinavi/