Skip to content

Commit 9402804

Browse files
authored
Merge pull request #50 from MekDrop/upgrade-readme
Improved README.md
2 parents f44d6b6 + 5c34022 commit 9402804

File tree

2 files changed

+118
-13
lines changed

2 files changed

+118
-13
lines changed

README.md

Lines changed: 116 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
[![License](https://img.shields.io/github/license/imponeer/smarty-image.svg)](LICENSE)
2-
[![GitHub release](https://img.shields.io/github/release/imponeer/smarty-image.svg)](https://github.com/imponeer/smarty-image/releases) [![Maintainability](https://api.codeclimate.com/v1/badges/c284ca86c6df6e98b9d0/maintainability)](https://codeclimate.com/github/imponeer/smarty-image/maintainability) [![PHP](https://img.shields.io/packagist/php-v/imponeer/smarty-image.svg)](http://php.net)
3-
[![Packagist](https://img.shields.io/packagist/dm/imponeer/smarty-image.svg)](https://packagist.org/packages/imponeer/smarty-image)
1+
[![License](https://img.shields.io/github/license/imponeer/smarty-image.svg)](LICENSE) [![GitHub release](https://img.shields.io/github/release/imponeer/smarty-image.svg)](https://github.com/imponeer/smarty-image/releases) [![PHP](https://img.shields.io/packagist/php-v/imponeer/smarty-image.svg)](http://php.net) [![Packagist](https://img.shields.io/packagist/dm/imponeer/smarty-image.svg)](https://packagist.org/packages/imponeer/smarty-image) [![Smarty version requirement](https://img.shields.io/packagist/dependency-v/imponeer/smarty-image/smarty%2Fsmarty)](https://smarty-php.github.io)
42

53
# Smarty Image
64

7-
Some [Smarty](https://smarty.net) syntax plugins for operations with images.
5+
A modern [Smarty](https://smarty.net) 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.
86

97
## Installation
108

@@ -16,23 +14,93 @@ composer require imponeer/smarty-image
1614

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

19-
## Registering in Smarty
17+
## Setup
2018

21-
For Smarty v5 and never, use the new extension system:
19+
### Basic Setup
20+
21+
For Smarty v5 and newer, use the new extension system:
2222

2323
```php
2424
$smarty = new \Smarty\Smarty();
25-
// For $psrCacheAdapter value use PSR-16 cache adapter, for example Symfony\Component\Cache\Adapter\ArrayAdapter
25+
// For $psrCacheAdapter value use PSR-6 cache adapter, for example Symfony\Component\Cache\Adapter\ArrayAdapter
2626
$smarty->addExtension(
2727
new \Imponeer\Smarty\Extensions\Image\SmartyImageExtension($psrCacheAdapter)
2828
);
2929
```
3030

3131
For older Smarty use [v2.0 version of this plugin](https://github.com/imponeer/smarty-image/tree/v2.0.2).
3232

33-
## Using from templates
33+
### Using with Symfony Container
34+
35+
When using Symfony's dependency injection container, you can register the extension as a service:
36+
37+
```yaml
38+
# config/services.yaml
39+
services:
40+
Imponeer\Smarty\Extensions\Image\SmartyImageExtension:
41+
arguments:
42+
$cache: '@cache.app'
43+
tags:
44+
- { name: 'smarty.extension' }
45+
```
46+
47+
Then inject it into your Smarty instance:
48+
49+
```php
50+
// In your controller or service
51+
public function __construct(
52+
private Smarty $smarty,
53+
private SmartyImageExtension $imageExtension
54+
) {
55+
$this->smarty->addExtension($this->imageExtension);
56+
}
57+
```
58+
59+
### Using with PHP-DI
60+
61+
With PHP-DI container, configure the extension in your container definitions:
3462

35-
To resize images from smarty You can use resized_image function:
63+
```php
64+
use Psr\Cache\CacheItemPoolInterface;
65+
use Imponeer\Smarty\Extensions\Image\SmartyImageExtension;
66+
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
67+
68+
return [
69+
CacheItemPoolInterface::class => \DI\create(FilesystemAdapter::class),
70+
SmartyImageExtension::class => \DI\create()
71+
->constructor(\DI\get(CacheItemPoolInterface::class)),
72+
73+
Smarty::class => \DI\factory(function (SmartyImageExtension $imageExtension) {
74+
$smarty = new Smarty();
75+
$smarty->addExtension($imageExtension);
76+
return $smarty;
77+
})
78+
];
79+
```
80+
81+
### Using with League Container
82+
83+
With League Container, register the services like this:
84+
85+
```php
86+
use League\Container\Container;
87+
use Psr\Cache\CacheItemPoolInterface;
88+
use Symfony\Component\Cache\Adapter\ArrayAdapter;
89+
use Imponeer\Smarty\Extensions\Image\SmartyImageExtension;
90+
91+
$container = new Container();
92+
93+
$container->add(CacheItemPoolInterface::class, ArrayAdapter::class);
94+
$container->add(SmartyImageExtension::class)
95+
->addArgument(CacheItemPoolInterface::class);
96+
97+
$container->add(Smarty::class)
98+
->addMethodCall('addExtension', [SmartyImageExtension::class]);
99+
```
100+
101+
## Usage
102+
103+
To resize images from Smarty templates, you can use the `resized_image` function:
36104
```smarty
37105
{resized_image file="/images/image.jpg" height=70}
38106
```
@@ -51,8 +119,45 @@ This function supports such arguments:
51119

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

122+
## Development
123+
124+
This project uses modern PHP development tools and practices:
125+
126+
### Running Tests
127+
```bash
128+
composer test
129+
```
130+
131+
### Code Style
132+
The project follows PSR-12 coding standards. Check code style with:
133+
```bash
134+
composer phpcs
135+
```
136+
137+
Fix code style issues automatically:
138+
```bash
139+
composer phpcbf
140+
```
141+
142+
### Static Analysis
143+
Run PHPStan for static code analysis:
144+
```bash
145+
composer phpstan
146+
```
147+
148+
## Documentation
149+
150+
API documentation is automatically generated and available in the [project's wiki](https://github.com/imponeer/smarty-image/wiki). For more detailed information about the classes and methods, please refer to the [project wiki](https://github.com/imponeer/smarty-image/wiki).
151+
54152
## How to contribute?
55153

56-
If you want to add some functionality or fix bugs, you can fork, change and create pull request. If you not sure how this works, try [interactive GitHub tutorial](https://skills.github.com).
154+
We welcome contributions! If you want to add functionality or fix bugs:
155+
156+
1. Fork the repository
157+
2. Create a feature branch from `main`
158+
3. Make your changes following the coding standards
159+
4. Add or update tests as needed
160+
5. Run the test suite to ensure everything works
161+
6. Submit a pull request with a clear description of your changes
57162

58-
If you found any bug or have some questions, use [issues tab](https://github.com/imponeer/smarty-image/issues) and write there your questions.
163+
For bug reports or feature requests, please use the [issues tab](https://github.com/imponeer/smarty-image/issues) and provide as much detail as possible.

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "imponeer/smarty-image",
3-
"description": "Smarty plugin that adds some image related template syntax enchaments",
3+
"description": "Smarty plugin that adds some image related template syntax enchantments",
44
"type": "library",
55
"require": {
66
"php": "^8.3",
7-
"smarty/smarty": "^4.0|^5.0",
7+
"smarty/smarty": "^5.0",
88
"intervention/image": "^3",
99
"psr/cache": "^1.0|^2.0|^3.0",
1010
"ext-json": "*",

0 commit comments

Comments
 (0)