承接 jorisvanw/cloudconvert-php 相关项目开发

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

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

jorisvanw/cloudconvert-php

Composer 安装命令:

composer require jorisvanw/cloudconvert-php

包简介

PHP Wrapper for CloudConvert APIs [For Guzzlehttp 6]

README 文档

README

This is a lightweight wrapper for the CloudConvert API.

Feel free to use, improve or modify this wrapper! If you have questions contact us or open an issue on GitHub.

Build Status

Quickstart

<?php
require __DIR__ . '/vendor/autoload.php';
use \CloudConvert\Api;
$api = new Api("your_api_key");

$api->convert([
        'inputformat' => 'png',
        'outputformat' => 'pdf',
        'input' => 'upload',
        'file' => fopen('./tests/input.png', 'r'),
    ])
    ->wait()
    ->download('./tests/output.pdf');
?>

You can use the CloudConvert API Console to generate ready-to-use PHP code snippets using this wrapper.

Install with Composer

To download this wrapper and integrate it inside your PHP application, you can use Composer.

Add the repository in your composer.json file or, if you don't already have this file, create it at the root of your project with this content:

{
    "name": "Example Application",
    "description": "This is an example",
    "require": {
        "cloudconvert/cloudconvert-php": "dev-master"
    }
}

Then, you can install CloudConvert APIs wrapper and dependencies with:

php composer.phar install

This will install cloudconvert/cloudconvert-php to ./vendor, along with other dependencies including autoload.php.

Install manually

If you don't want to use composer, you can download the cloudconvert-php.phar release from the Releases tab on GitHub. The .phar file is basically a ZIP file which contains all dependencies and can be used as shown here:

<?php
require 'phar://cloudconvert-php.phar/vendor/autoload.php';
use \CloudConvert\Api;
$api = new Api("your_api_key");

//...

Using with Callback

This is a non-blocking example for server side conversions: The public URL of the input file and a callback URL is sent to CloudConvert. CloudConvert will trigger this callback URL if the conversion is finished.

<?php
require __DIR__ . '/vendor/autoload.php';
use \CloudConvert\Api;
$api = new Api("your_api_key");

$process = $api->createProcess([
    'inputformat' => 'png',
    'outputformat' => 'jpg',
]);

$process->start([
    'outputformat' => 'jpg',
    'converteroptions' => [
        'quality' => 75,
    ],
    'input' => 'download',
    'file' => 'https://cloudconvert.com/blog/wp-content/themes/cloudconvert/img/logo_96x60.png',
    'callback' => 'http://_INSERT_PUBLIC_URL_TO_/callback.php'
]);

echo "Conversion was started in background :-)";
?>

Using the following callback.php you can retrieve the finished process and download the output file.

<?php
require __DIR__ . '/vendor/autoload.php';
use \CloudConvert\Api;
use \CloudConvert\Process;
$api = new Api("your_api_key");

$process = new Process($api, $_REQUEST['url']);
$process->refresh()->download("output.jpg");

?>

User uploaded input files

If your input files are provided by your users, you can let your users directly upload their files to CloudConvert (instead of uploading them to your server first and afterwards sending them to CloudConvert). The following example shows how this can be implemented easily.

<?php
require __DIR__ . '/vendor/autoload.php';
use \CloudConvert\Api;
$api = new Api("your_api_key");

$process = $api->createProcess([
    'inputformat' => 'png',
    'outputformat' => 'jpg',
]);

$process->start([
    'input' => 'upload',
    'outputformat' => 'jpg',
    'converteroptions' => [
        'quality' => 75,
    ],
    'callback' => 'http://_INSERT_PUBLIC_URL_TO_/callback.php'
]);
?>
<form action="<?=$process->upload->url?>" method="POST" enctype="multipart/form-data">
     <input type="file" name="file">
     <input type="submit">
</form>

Download of multiple output files

In some cases it might be possible that there are multiple output files (e.g. converting a multi-page PDF to JPG). You can download them all to one directory using the downloadAll() method.

<?php
require __DIR__ . '/vendor/autoload.php';
use \CloudConvert\Api;
$api = new Api("your_api_key");

$process = $api->convert([
        'inputformat' => 'pdf',
        'outputformat' => 'jpg',
        'converteroptions' => [
            'page_range' => '1-3',
        ],
        'input' => 'download',
        'file' => fopen('./tests/input.pdf', 'r'),
    ])
    ->wait()
    ->downloadAll('./tests/');
?>

Alternatively you can iterate over $process->output->files and download them seperately using $process->download($localfile, $remotefile).

Catching Exceptions

The following example shows how to catch the different exception types which can occur at conversions:

<?php
require __DIR__ . '/vendor/autoload.php';
use \CloudConvert\Api;

$api = new Api("your_api_key");

try {

    $api->convert([
        'inputformat' => 'pdf',
        'outputformat' => 'jpg',
        'input' => 'upload',
        'file' => fopen('./tests/input.pdf', 'r'),
    ])
        ->wait()
        ->downloadAll('./tests/');

} catch (\CloudConvert\Exceptions\ApiBadRequestException $e) {
    echo "Something with your request is wrong: " . $e->getMessage();
} catch (\CloudConvert\Exceptions\ApiConversionFailedException $e) {
    echo "Conversion failed, maybe because of a broken input file: " . $e->getMessage();
}  catch (\CloudConvert\Exceptions\ApiTemporaryUnavailableException $e) {
    echo "API temporary unavailable: " . $e->getMessage() ."\n";
    echo "We should retry the conversion in " . $e->retryAfter . " seconds";
} catch (Exception $e) {
    // network problems, etc..
    echo "Something else went wrong: " . $e->getMessage() . "\n";
}

How to build the documentation?

Documentation is based on phpdocumentor. To install it with other quality tools, you can install local npm project in a clone a project

git clone https://github.com/LunawebLtd/cloudconvert-php.git
cd cloudconvert-php
php composer.phar install
npm install

To generate documentation, it's possible to use directly:

grunt phpdocs

Documentation is available in docs/ directory.

How to run tests?

Tests are based on phpunit. To install it with other quality tools, you can install local npm project in a clone a project

git https://github.com/LunawebLtd/cloudconvert-php.git
cd cloudconvert-php
php composer.phar install
npm install

Edit phpunit.xml file with your API Key to pass functionals tests. Then, you can run directly unit and functionals tests with grunt.

grunt

Resources

jorisvanw/cloudconvert-php 适用场景与选型建议

jorisvanw/cloudconvert-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.45k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 02 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 jorisvanw/cloudconvert-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jorisvanw/cloudconvert-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 jorisvanw/cloudconvert-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 90
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2016-02-18