承接 setono/sylius-image-optimizer-plugin 相关项目开发

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

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

setono/sylius-image-optimizer-plugin

Composer 安装命令:

composer require setono/sylius-image-optimizer-plugin

包简介

Sylius plugin that optimizes your images

README 文档

README

Latest Version Latest Unstable Version Software License Build Status Code Coverage

Optimize the images in your Sylius store! Works only with kraken.io at the moment, but will work with other vendors in the future.

Have you seen this message from Google page speed tools: "Serve images in next-gen formats", this is the plugin to use.

It will both optimize your jpegs, but also convert them to webp and serve the webp images to browsers that support webp (i.e. Chrome).

Installation

Step 1: Download the plugin

$ composer require setono/sylius-image-optimizer-plugin

This will also install the Kraken.io Bundle which is need for configuring the API keys.

Step 2: Enable the plugin

Then, enable the plugin by adding it to the list of registered plugins/bundles in the config/bundles.php file of your project:

Make sure you add it before SyliusGridBundle, otherwise you'll get You have requested a non-existent parameter "setono_sylius_image_optimizer.model.savings.class". exception.

<?php
# config/bundles.php

return [
    // ...
    Setono\SyliusImageOptimizerPlugin\SetonoSyliusImageOptimizerPlugin::class => ['all' => true],
    Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
    // ...
];

Step 3: Configure the plugin

Add the resources (image resources) that should be optimized. In the example below a product image is optimized and the filter sets that are optimized are the default frontend filter sets for products.

This is also the step where you need your API key and secret from kraken.io.

# .env.local
KRAKEN_API_KEY=YOUR API KEY
KRAKEN_API_SECRET=YOUR API SECRET
# config/packages/setono_kraken_io.yaml
setono_kraken_io:
    api_key: "%env(KRAKEN_API_KEY)%"
    api_secret: "%env(KRAKEN_API_SECRET)%"
# config/packages/setono_sylius_image_optimizer.yaml
imports:
    - { resource: "@SetonoSyliusImageOptimizerPlugin/Resources/config/app/config.yaml" }

setono_sylius_image_optimizer:
    image_resources:
        sylius.product_image:
            # Run "php bin/console debug:config liip_imagine filter_sets" to find the filter sets configured in your app
            - sylius_shop_product_large_thumbnail
            - sylius_shop_product_thumbnail
            - sylius_shop_product_small_thumbnail
            - sylius_shop_product_tiny_thumbnail
            - sylius_shop_product_original
# config/routes/setono_sylius_image_optimizer.yaml
setono_sylius_image_optimizer:
    resource: "@SetonoSyliusImageOptimizerPlugin/Resources/config/routes.yaml"

Step 4: Configure Symfony Messenger

If you haven't used Symfony Messenger before, you need to specify a default bus like so:

# config/packages/messenger.yaml

framework:
    messenger:
        default_bus: setono_sylius_image_optimizer.command_bus

Step 4.1: Using asynchronous transport (optional, but recommended)

All commands in this plugin will extend the CommandInterface and all events will extend the EventInterface.

Therefore, you can route all commands and events easily by adding this to your Messenger config:

# config/packages/messenger.yaml
framework:
   messenger:
       routing:
           # Route all command messages to the async transport
           # This presumes that you have already set up an 'async' transport
           'Setono\SyliusImageOptimizerPlugin\Message\Command\CommandInterface': async
           'Setono\SyliusImageOptimizerPlugin\Message\Event\EventInterface': async

Step 5: Extend image resources

The following example is for the product images. You should follow this procedure for all image resources you want to optimize.

<?php
// src/Entity/Product/ProductImage.php
declare(strict_types=1);

namespace App\Entity\Product;

use Doctrine\ORM\Mapping as ORM;
use Setono\SyliusImageOptimizerPlugin\Model\OptimizableInterface;
use Setono\SyliusImageOptimizerPlugin\Model\OptimizableTrait;
use Sylius\Component\Core\Model\ProductImage as BaseProductImage;

/**
 * @ORM\Table(name="sylius_product_image")
 * @ORM\Entity()
 */
final class ProductImage extends BaseProductImage implements OptimizableInterface
{
    use OptimizableTrait;
}
# config/packages/_sylius.yaml

sylius_core:
    resources:
        product_image:
            classes:
                model: App\Entity\Product\ProductImage

Step 6: Update database

Last step is to create a diff for your current database schema and migrate that schema.

$ php bin/console doctrine:migrations:diff
$ php bin/console doctrine:migrations:migrate

Usage

Now run this command to optimize your images:

$ php bin/console setono:sylius-image-optimizer:optimize

Testing

If you want to test this plugin you can setup ngrok to tunnel requests to your localhost:

  1. Download and install ngrok
  2. Run your local web server: symfony serve --allow-http (the allow-http is important since ngrok always tunnels to the non secure localhost)
  3. Run ngrok: ngrok http 8000

setono/sylius-image-optimizer-plugin 适用场景与选型建议

setono/sylius-image-optimizer-plugin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 28.83k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2020 年 02 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 setono/sylius-image-optimizer-plugin 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 8
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-12