rosell-dk/webp-convert-cloud-service

将JPEG和PNG转换为WebP的云服务

2.0.1 2019-06-30 08:28 UTC

This package is auto-updated.

Last update: 2024-08-24 20:39:10 UTC


README

此库允许您设置自己的WebP转换云服务。这样您可以免费拥有一个云转换器。您不必担心许可证到期或被盗用。并且您可以完全控制它(以及停机时间)。

设置云服务后,您可以使用它将jpeg和png图像转换为webp图像。您可以使用webp-convert或其实现之一,例如上述的Wordpress插件WebP Express

作为安装此库的替代方案,您也可以安装Wordpress和上述提到的WebP Express插件。WebP Express可以被配置为作为转换服务。该插件实际上使用此库来实现该功能。

安装

1. 使用Composer要求库

composer require rosell-dk/webp-convert-cloud-service

2. 创建一个脚本,通过配置选项调用库

以下是一个入门示例

<?php
require 'vendor/autoload.php';

use \WebPConvertCloudService\WebPConvertCloudService;

$options = [
    // Set dir for storing converted images temporarily
    // Make sure to create that dir, with permissions for web server to write.
    // You can __DIR__ to get same dir as this script, or "dirname(__DIR__)" to get parent dir of the script,
    'destination-dir' => dirname(__DIR__) . '/conversions',

    // Set acccess restrictions
    'access' => [
        'whitelist' => [
            [
                'ip' => '*',
                'api-key' => 'my dog is white',
                'require-api-key-to-be-crypted-in-transfer' => false
            ]
        ]
    ],

    // Optionally set webp-convert options
    'webp-convert' => [
        'converters' => ['cwebp', 'gd', 'imagick'],
        'converter-options' => [
            'cwebp' => [
                'try-common-system-paths' => true,
                'try-supplied-binary-for-os' => true,
                'use-nice' => true
            ]
        ]
    ]
];

$wpc = new WebPConvertCloudService();
$wpc->handleRequest($options);
?>

3. 测试是否工作

您可以使用curl调用API。首先,您可能要做的是测试服务是否可用。您可以通过请求api-version来做到这一点,因为这不需要任何授权。

curl --form action="api-version" http://wpc.example.com/wpc.php

接下来,您可以测试访问。如果您已将require-api-key-to-be-crypted-in-transfer设置为false,您可以像这样测试访问

curl --form action="check-access" --form api-key="my dog is white" http://wpc.example.com/wpc.php

最后,您可以这样做进行测试转换。首先,在您的当前目录中放置一个文件test.jpg,然后运行

curl --form action="convert" --form api-key="my dog is white" --form file=@test.jpg http://wpc.example.com/wpc.php > test.webp

如果您得到一个损坏的文件,那么这可能是由于输出包含错误消息。要查看它,再次运行上述命令,但移除输出到文件的管道。

您可能不需要了解API的更多内容。但万一需要,请查看docs/api.md

疯狂科学家工具

如果您喜欢这个软件,请随意进行一些秘密实验并疯狂一把。如果喜欢的话。