定制 codeinwp/optimole-sdk 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

codeinwp/optimole-sdk

Composer 安装命令:

composer require codeinwp/optimole-sdk

包简介

SDK for Optimole cloud-based image optimization service

README 文档

README

Actions Status

The Optimole PHP SDK makes it easy for PHP developers to integrate Optimole cloud-based image optimization service in their PHP project.

Requirements

  • PHP >= 7.4

Installation

Install the Optimole PHP SDK in your project using composer:

$ composer require codeinwp/optimole-sdk

Usage

To begin, you need to create an account on Optimole and get your API key.

Initializing the SDK

You can then initialize the SDK with your API key using the Optimole facade:

use Optimole\Sdk\Optimole;

Optimole::init('your-api-key', $options);

The second argument of the init method is optional. It allows you to pass options to the SDK that can be used to configure it. These options are:

  • base_domain: The base domain to connect to Optimole's API. Default is i.optimole.com.
  • cache_buster: A string value that will be appended to the URL of the optimized assets to bust Optimole's cache.
  • dashboard_api_url: The URL of the dashboard API. Default is https://dashboard.optimole.com/api.
  • dashboard_api_key: The API key to use for the dashboard API.
  • upload_api_credentials: An array with the credentials to use for the upload API. The array should contain the keys userKey and secret. The default is empty and the SDK will use the API key provided in the init method to fetch them from the dashboard API.
  • upload_api_url: The URL of the upload API. Default is https://generateurls-prod.i.optimole.com/upload.

Optimizing Images and Assets

The Optimole facade is your starting point for creating optimized images or other assets. You can control the optimization properties using the fluent interface provided by the SDK. Here's an example of how to optimize an image by changing its quality and cropping it:

use Optimole\Sdk\Optimole;

$image = Optimole::image('https://example.com/image.jpg')->quality(80)->resize('crop');

You can get the optimized image URL using the getUrl method or casting the object to a string:

echo $image->getUrl();
echo (string) $image;

Offloading Images to Optimole

The SDK also provides a way to offload images to Optimole. This is useful when you want to serve images from Optimole's content delivery network. Here's an example of how to offload an image:

use Optimole\Sdk\Optimole;

$imageId = Optimole::offload()->uploadImage('path/to/image.jpg', 'https://url/to/image.jpg');

This will upload the image to Optimole and return the image ID. You can then use this image ID to interact with the image. For example, you can get the URL of the offloaded image:

use Optimole\Sdk\Optimole;

$imageUrl = Optimole::offload()->getImageUrl($imageId);

Contributing

Install dependencies using composer and run the test suite:

$ composer install
$ vendor/bin/phpunit

codeinwp/optimole-sdk 适用场景与选型建议

codeinwp/optimole-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.44k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2024 年 03 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 5
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-25