imponeer/smarty-image 问题修复 & 功能扩展

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

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

imponeer/smarty-image

Composer 安装命令:

composer require imponeer/smarty-image

包简介

Smarty plugin that adds some image related template syntax enchantments

README 文档

README

License GitHub release PHP Packagist Smarty version requirement

Smarty Image

A modern Smarty extension that provides image resizing capabilities with built-in caching. This extension allows you to resize images directly from your Smarty templates using the resized_image function.

Installation

To install and use this package, we recommend to use Composer:

composer require imponeer/smarty-image

Otherwise, you need to include manually files from src/ directory.

Setup

Basic Setup

For Smarty v5 and newer, use the new extension system:

$smarty = new \Smarty\Smarty();
// For $psrCacheAdapter value use PSR-6 cache adapter, for example Symfony\Component\Cache\Adapter\ArrayAdapter
$smarty->addExtension(
    new \Imponeer\Smarty\Extensions\Image\SmartyImageExtension($psrCacheAdapter)
);

For older Smarty use v2.0 version of this plugin.

Using with Symfony Container

When using Symfony's dependency injection container, you can register the extension as a service:

# config/services.yaml
services:
    Imponeer\Smarty\Extensions\Image\SmartyImageExtension:
        arguments:
            $cache: '@cache.app'
        tags:
            - { name: 'smarty.extension' }

Then inject it into your Smarty instance:

// In your controller or service
public function __construct(
    private Smarty $smarty,
    private SmartyImageExtension $imageExtension
) {
    $this->smarty->addExtension($this->imageExtension);
}

Using with PHP-DI

With PHP-DI container, configure the extension in your container definitions:

use Psr\Cache\CacheItemPoolInterface;
use Imponeer\Smarty\Extensions\Image\SmartyImageExtension;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

return [
    CacheItemPoolInterface::class => \DI\create(FilesystemAdapter::class),
    SmartyImageExtension::class => \DI\create()
        ->constructor(\DI\get(CacheItemPoolInterface::class)),

    Smarty::class => \DI\factory(function (SmartyImageExtension $imageExtension) {
        $smarty = new Smarty();
        $smarty->addExtension($imageExtension);
        return $smarty;
    })
];

Using with League Container

With League Container, register the services like this:

use League\Container\Container;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Imponeer\Smarty\Extensions\Image\SmartyImageExtension;

$container = new Container();

$container->add(CacheItemPoolInterface::class, ArrayAdapter::class);
$container->add(SmartyImageExtension::class)
    ->addArgument(CacheItemPoolInterface::class);

$container->add(Smarty::class)
    ->addMethodCall('addExtension', [SmartyImageExtension::class]);

Usage

To resize images from Smarty templates, you can use the resized_image function:

  {resized_image file="/images/image.jpg" height=70}

This function supports such arguments:

Argument Required Default value Description
file yes Image file to resize
width if height is not specified Resized image width
height if width is not specified Resized image height
fit no outside Method used for resize. Supported fill, inside, outside
href or link no if specified and return is set to image, will output generated HTML as image with link to this specific location
basedir no $_SERVER['DOCUMENT_ROOT'] Base dir where to look for image files
return no image Returns result as HTML tag if value is image, or as resized image URI if value is url.

All extra arguments will be rendered into image tag, if return mode is image.

Development

This project uses modern PHP development tools and practices:

Running Tests

composer test

Code Style

The project follows PSR-12 coding standards. Check code style with:

composer phpcs

Fix code style issues automatically:

composer phpcbf

Static Analysis

Run PHPStan for static code analysis:

composer phpstan

Documentation

API documentation is automatically generated and available in the project's wiki. For more detailed information about the classes and methods, please refer to the project wiki.

How to contribute?

We welcome contributions! If you want to add functionality or fix bugs:

  1. Fork the repository
  2. Create a feature branch from main
  3. Make your changes following the coding standards
  4. Add or update tests as needed
  5. Run the test suite to ensure everything works
  6. Submit a pull request with a clear description of your changes

For bug reports or feature requests, please use the issues tab and provide as much detail as possible.

imponeer/smarty-image 适用场景与选型建议

imponeer/smarty-image 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.79k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 02 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 imponeer/smarty-image 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-02-03