PHP code example of tlamedia / grabzit-bundle
1. Go to this page and download the library: Download tlamedia/grabzit-bundle library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tlamedia / grabzit-bundle example snippets
// config/bundles.php
return [
//...
Tla\GrabzitBundle\TlaGrabzitBundle::class => ['all' => true],
//...
];
namespace App\Service;
use Symfony\Component\DependencyInjection\ContainerInterface as Container;
class ThumbnailGenerator
{
private $container;
public function __construct(Container $container)
{
$this->router = $router;
$this->container = $container;
}
public function generateThumbnail($domain)
{
$grabzItHandlerUrl = 'https://www.my-grabzit-thumbnail-site.com/api/thumbmail-ready';
$options = $this->container->get('tla_grabzit.imageoptions');
$options->setBrowserWidth(1024);
$options->setBrowserHeight(768);
$options->setFormat("png");
$options->setWidth(320);
$options->setHeight(240);
$options->setCustomId($domain);
$grabzIt = $this->container->get('tla_grabzit.client');
$grabzIt->URLToImage("http://".$domain, $options);
$grabzIt->Save($grabzItHandlerUrl);
try {
$grabzIt->URLToImage("http://".$domain, $options);
$grabzIt->Save($grabzItHandlerUrl);
$result = true;
} catch (\Throwable $t) {
$result = false;
}
return $result;
}
}
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class ApiController extends Controller
{
public function thumbnailReadyAction(Request $request)
{
$id = urldecode($request->query->get('id'));
$customId = $request->query->get('customid');
$thumbnailFormat = $request->query->get('format');
if ($id && $customId && $thumbnailFormat) {
$grabzItApplicationKey = $this->container->getParameter('tla_grabzit.key');
if (0 === strpos($id, $grabzItApplicationKey)) {
$grabzIt = $this->container->get('tla_grabzit.client');
$result = $grabzIt->GetResult($id);
if ($result) {
$rootPath = $this->get('kernel')->getRootDir() . '/../';
$thumbnailsPath = $rootPath . 'var/thumbnails/';
$fileName = $customId. '.' .$thumbnailFormat;
file_put_contents($thumbnailsPath . $fileName, $result);
} else {
throw $this->createNotFoundException('GrabzIt did not return a file');
}
} else {
throw $this->createNotFoundException('Wrong key - Unauthorized access');
}
} else {
throw $this->createNotFoundException('Missing parameters');
}
return new Response(null, 200);
}
}