जबकि GrabzIt's PHP लाइब्रेरी एक पुस्तकालय प्रदान करने पर केंद्रित है जो किसी भी PHP परियोजना में उपयोग किया जा सकता है। Symfony PHP परियोजनाओं को एक अनूठे तरीके से एक साथ रखा जाता है जिसमें थोड़ा और काम करने की आवश्यकता होती है।
सिम्फनी सबसे बड़ी PHP फ्रेमवर्क में से एक है जिसका उपयोग वर्तमान में पुस्तकालयों और घटकों के पुन: प्रयोज्य सेट प्रदान करके वेब विकास को गति देता है। जो GrabzIt अब का एक हिस्सा है, Torben Lundsgaard के लिए धन्यवाद TLAMedia जिन्होंने सिम्फनी के लिए GrabzIt का एक बंडल बनाया। इस ओपन सोर्स सॉफ्टवेयर का उपयोग करता है एमआईटी लाइसेंस.
GrabzIt बंडल को प्राप्त करने के लिए आपको पहले इसे संगीतकार के साथ स्थापित करना होगा।
composer require tlamedia/grabzit-bundle
फिर इसे अपने कर्नेल में जोड़ें।
public function registerBundles()
{
$bundles = array(
//...
new Tla\GrabzitBundle\TlaGrabzitBundle(),
//…
विन्यास
जाओ अपने एपीआई कुंजी और गुप्त और उन्हें अपने विन्यास फाइल में जोड़ें।
# config.yml
tla_grabzit:
key: 'Sign in to view your Application Key'
secret: 'Sign in to view your Application Secret'
बंडल कई सेवाओं को पंजीकृत करता है जिसे उपयुक्त GrabzIt क्लास कहा जाता है।
कैप्चर कैसे उत्पन्न करें
सिम्फनी फ्रेमवर्क में थंबनेल कैसे उत्पन्न करें, इसका एक उदाहरण।
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($url)
{
$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($url, $options);
$grabzIt->Save($grabzItHandlerUrl);
try {
$grabzIt->URLToImage($url, $options);
$grabzIt->Save($grabzItHandlerUrl);
$result = true;
} catch (\Throwable $t) {
$result = false;
}
return $result;
}
}
एक हैंडलर के साथ कैप्चर कैसे प्राप्त करें
सिम्फनी फ्रेमवर्क में हैंडलर का उपयोग करके GrabzIt से कैप्चर कैसे प्राप्त करें, इसका एक उदाहरण। बेशक आपको इसे अपनी आवश्यकताओं से मेल खाने के लिए बदलना होगा।
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);
}
}
इस सहायता लेख का विस्तार किया गया है GitHub पर विस्तृत इस बंडल के लिए मदद.