Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nikocraft's avatar

how do I use php library with Laravel that was not made for Laravel

I want to use GrabzIt php library http://grabz.it/api/php/ it allows me to take screenshots of website or turn videos into gifs. I have included it in my composer.json like this

"grabzit/grabzit":"3.0.0"

and it has installed. They give example how to use it when using normal php, they do this:

include("lib/GrabzItClient.class.php");
include("config.php");

and then go on using it like this:

$grabzIt = new GrabzItClient($grabzItApplicationKey, $grabzItApplicationSecret);

But how should I do that in Laravel?

0 likes
11 replies
ohffs's avatar

If you installed it via composer it should be in the vendor/ directory somewhere. There should (hopefully!) be a composer.json somewhere inside it's own folder. Have a look for something like :

"autoload": {
        "psr-0": {
            "GrabzIt\\": ""
        },

That indicates you can use it like :

<?php

use GrabzIt\Client;

class Whatever
{
  public function something() {
    $client = new Client($options);
  }
}

You might need to do some digging though :-/

primordial's avatar

@maxnb They are not using any auto-loading standard. Having quickly peeked at the code it would be quite easy to create a PSR/4 package by adding the namespaces and updating their composer.json file. If you do I would suggest you make a pull request afterwards.

If you have never written a package or feel unable I can only suggest using the require statements as described but update your path lines to reflect the fact the code exists inside your vendor folder.

nikocraft's avatar

This is how their composer.json looks like

{
    "name": "grabzit/grabzit",
    "type": "library",
    "keywords": ["screenshots","PDF","HTML","table","capture","PNG","JPG","BMP","TIFF","API","web","images","videos","animated gif","csv","xlsx","video conversion"],
    "homepage": "http://grabz.it/", 
    "description": "Use our API to allow your app to create images and PDF's from URL's or raw HTML. Additionally GrabzIt allows you to convert online videos into animated GIF's or HTML tables into CSV's.",
    "license": "MIT",
    "version":"3.0.0",
    "support": {
        "issues": "http://grabz.it/support/"
    },
    "require": {
        "php": ">=5.0.0"
    }
}

@primordial I've never created package before, I wouldnt know where to start. Do you mean something like this:

include("grabzit/grabzit/lib/GrabzItClient.class.php");
include("grabzit/grabzi/tconfig.php");
ohffs's avatar

Cripes - just installed it and yep, that's not nice :'-/

nikocraft's avatar

@ohffs can you help me solve this? I can pay you if that would be worth your time?

primordial's avatar

Their composer.json lacks a line similar to that described by @ohffs hence Hobsons Choice. Try something along the lines of

include( app_path().'vendor/grabzit/grabzit/lib/GrabzItClient.class.php');

That line may need to be tweaked, not sure if app_path() is still valid in L 5.3 but hopefully you get the point.

Good luck.

PS> Writing poackages is very very simple. Daunting at first, stupidly easy when you know how. That repo is a prime candidate.

ohffs's avatar

Go with what @primordial says - you should be able to get something going even if it's a bit ugly for now :-)

If you search this site for 'package' you should find some videos about making one. I think this series is the newest one that goes through the process - hopefully that'll help :-)

nikocraft's avatar

ok thanks guys I managed to import it without any errors and had to use base_path() instead of app_path()

1 like
primordial's avatar

@maxnd

I think you will have issues with configuration, the config file exists inside the vendor folder and will be rewritten everytime you install. I may package it up over the weekend. 6000+ downloads on packagist.

nikocraft's avatar

notify me if you do package it, thanks :)

Please or to participate in this conversation.