承接 tlamedia/grabzit-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tlamedia/grabzit-bundle

最新稳定版本:2.1.1

Composer 安装命令:

composer require tlamedia/grabzit-bundle

包简介

The GrabzitBundle integrates the GrabzIt PHP library with Symfony, allowing you to interact with the GrabzIt API in your Symfony projects.

README 文档

README

The GrabzitBundle integrates the GrabzIt PHP library with Symfony.

Latest Stable Version Build Status License

Installation

Get the bundlle:

composer require tlamedia/grabzit-bundle

Then enable it in your kernel:

// config/bundles.php
return [
    //...
    Tla\GrabzitBundle\TlaGrabzitBundle::class => ['all' => true],
    //...
];

Configuration

Configure the API key to use:

# config.yml
tla_grabzit:
    key: 'Your_Application_Key' # Replace with your own
    secret: 'Your_Application_Secret' # Replace with your own

Usage

The bundle registers the services tla_grabzit.imageoptions, tla_grabzit.pdfoptions, tla_grabzit.docxoptions, tla_grabzit.animationoptions, tla_grabzit.tableoptions and tla_grabzit.client, which allows you to use the GrabzIt API.

Request a thumbnail from a service

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;
    }
}

Recieve thumbnail with GrabzIt handler in a controller

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);
    }
}

Documentation

Detailed documentation on how to access each API method can be found in the documentation on the GrabzIt website

License

This package is available under the MIT license.

统计信息

  • 总下载量: 1.38k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-08-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固