zara-4/php-sdk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

zara-4/php-sdk

Composer 安装命令:

composer require zara-4/php-sdk

包简介

Helper classes used to interact with the Zara 4 API.

README 文档

README

PHP SDK for the Zara 4 Image Compression API. For more information see Zara 4 API documentation

Installation

Composer

You can install the SDK via Composer. Run the following command:

composer require zara-4/php-sdk

To use the SDK, use Composer's autoload:

require_once('vendor/autoload.php');

Authentication

All authentication with the Zara 4 API is handled by the PHP SDK. You simply need to provide your API_CLIENT_ID and API_CLIENT_SECRET when creating an API Client.

The Zara 4 API uses OAuth authentication, using access tokens to grant access. Access tokens are automatically generated and transparently refreshed by the PHP SDK.

Example API client setup

use Zara4\API\Client;

$apiClient = new Client(API_CLIENT_ID, API_CLIENT_SECRET);

To get your API credentials click here

Image Processing

The Zara 4 PHP SDK offers extensive support for image processing, making integrating Zara 4 into your PHP application very simple.

All authentication and communication with the Zara 4 API is automatically handled, meaning you can compress both remote and local images in just 4 lines of code.

Local Image

To process images on your local machine you should use a LocalImageRequest. This uploads the image from your machine to Zara 4 for processing.

Example usage

use Zara4\API\Client;
use Zara4\API\ImageProcessing\LocalImageRequest;
use Zara4\API\ImageProcessing\ProcessedImage;

$apiClient = new Client(API_CLIENT_ID, API_CLIENT_SECRET);
$originalImage = new LocalImageRequest("/path/to/original-image.jpg");
$processedImage = $apiClient->processImage($originalImage);
$apiClient->downloadProcessedImage($processedImage, "/where/to/save/compressed-image.jpg");

Remote Image

To process images from a remote location (such as a website url), you should use a RemoteImageRequest. This downloads the image from the remote location to Zara 4 for processing. The image url given must be publicly accessible.

Example usage

use Zara4\API\Client;
use Zara4\API\ImageProcessing\RemoteImageRequest;
use Zara4\API\ImageProcessing\ProcessedImage;

$apiClient = new Client(API_CLIENT_ID, API_CLIENT_SECRET);
$originalImage = new RemoteImageRequest("https://example.com/original-image.jpg");
$processedImage = $apiClient->processImage($originalImage);
$apiClient->downloadProcessedImage($processedImage, "/where/to/save/compressed-image.jpg");

Cloud Image

To process images from a cloud location (such as a Google Drive or Dropbox), you should use a CloudImageRequest. This downloads the image from the cloud location to Zara 4 for processing.

Example usage

use Zara4\API\Client;
use Zara4\API\ImageProcessing\CloudImageRequest;
use Zara4\API\ImageProcessing\ProcessedImage;

$apiClient = new Client(API_CLIENT_ID, API_CLIENT_SECRET);
$cloudDriveId = '905aaac0-06bb-11e7-83da-0b30de6ae4a2'; // Replace with your cloud drive id
$cloudFileId  = '0B_x2cioi5h8IX1NwYkNDcE96Tlk'; // Replace with the id of the file you wish to compress
$originalImage = new CloudImageRequest($cloudDriveId, $cloudFileId);
$processedImage = $apiClient->processImage($originalImage);
$apiClient->downloadProcessedImage($processedImage, "/where/to/save/compressed-image.jpg");

Options

You can customise how your images are processed with Zara 4 by altering your request options.

Example usage

use Zara4\API\Client;
use Zara4\API\ImageProcessing\LocalImageRequest;

$apiClient = new Client(API_CLIENT_ID, API_CLIENT_SECRET);
$originalImage = new LocalImageRequest("/path/to/original-image.jpg");

// Change request options
$originalImage->optimisationMode = OptimisationMode::HIGHEST;
$originalImage->outputFormat = OutputFormat::MATCH;
$originalImage->colourEnhancement = ColourEnhancement::IMPROVE_COLOUR;
$originalImage->resizeMode = ResizeMode::NONE;

$processedImage = $apiClient->processImage($originalImage);
$apiClient->downloadProcessedImage($processedImage, "/where/to/save/compressed-image.jpg");

Uploading Compressed Images To Cloud Storage

As well as downloading compressed images, you can also request from them to be uploaded to one of your Cloud Storage locations.

$request = new \Zara4\API\ImageProcessing\LocalImageRequest('test-images/001.jpg');

// --- --- --- ---

// The id of the cloud storage drive to upload to (Replace with your cloud drive id)
// You can manage your Cloud Storage from https://zara4.com/account/cloud-storage
$destinationDriveId = '905aaac0-06bb-11e7-83da-0b30de6ae4a2';

// The name the uploaded file should be given on you Cloud Storage
$destinationFileName = 'YOUR FILE NAME';

// You can also specify the folder the compressed image should be uploaded to
// If you do not wish to specify a parent folder, set $destinationParentId = null
$destinationParentId = 'xxxxxxxxxxxxxxxxxxx';

$request->uploadToCloud($destinationDriveId, $destinationFileName, $destinationParentId);

// --- --- --- ---

$response = $this->client->processImage($request);

zara-4/php-sdk 适用场景与选型建议

zara-4/php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 969 次下载、GitHub Stars 达 2, 最近一次更新时间为 2016 年 01 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Zara 4」 「Image Optimisation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 969
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-01-14