Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v6

- name: Install gifsicle
run: sudo apt-get update && sudo apt-get install -y gifsicle

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

* Added support for Symfony 8.2
* Replaced the `gifexception:optimize` command and `bin/optimizer.php` by the `castor optimize` task

## 1.11.1 (2026-05-26)

Expand Down
144 changes: 0 additions & 144 deletions Command/GifOptimizerCommand.php

This file was deleted.

20 changes: 7 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,14 @@ more gifs in [Resources/public/images/](Resources/public/images/), it will be ve

## Optimizing gifs

If you are adding gifs we strongly recommend optimizing them. There is a tool to aid with this (you will need to install [gifsicle](http://www.lcdf.org/gifsicle/)).
Every gif in the repository must be optimized and resized to 145px wide, the
test suite enforces it. Before committing a new gif, run the
[Castor](https://castor.jolicode.com/) task (you will need to install
[gifsicle](https://www.lcdf.org/gifsicle/)):

```shell
castor optimize
```
bin/optimizer.php
```

You can also run this command directly from your Symfony application:

```
bin/console gifexception:optimize
```

Although it would probably make more sense to use the former and push up the optimized gifs.

It uses [gifsicle](https://www.lcdf.org/gifsicle/) to optimize gifs via the [image-optimizer](https://github.com/psliwa/image-optimizer) library.

## Development

Expand All @@ -63,6 +56,7 @@ castor test # Run the test suite
castor cs # Fix PHP coding standards
castor cs --dry-run # Check PHP coding standards
castor phpstan # Run static analysis
castor optimize # Optimize and resize gifs
```

## Further documentation
Expand Down
5 changes: 0 additions & 5 deletions Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Joli\GifExceptionBundle\DependencyInjection\Loader\Configurator;

use Joli\GifExceptionBundle\Command\GifOptimizerCommand;
use Joli\GifExceptionBundle\EventListener\ReplaceImageListener;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

Expand All @@ -29,8 +28,4 @@
])
->tag('kernel.event_subscriber')
;
$container->services()
->set(GifOptimizerCommand::class)
->tag('console.command')
;
};
29 changes: 0 additions & 29 deletions bin/optimizer.php

This file was deleted.

14 changes: 14 additions & 0 deletions castor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Castor\Attribute\AsTask;

use function Castor\io;
use function Castor\run;

#[AsTask(description: 'Fix CS', aliases: ['cs'])]
Expand All @@ -36,3 +37,16 @@ function phpstan(): void
{
run('vendor/bin/phpstan analyse -c phpstan.neon');
}

#[AsTask(description: 'Optimize and resize gifs with gifsicle')]
function optimize(string $dir = 'Resources/public/images', int $width = 145, string $level = '-O3'): void
{
foreach (glob("{$dir}/*/*.gif") ?: [] as $gif) {
$before = filesize($gif);
run(['gifsicle', '-b', $level, "--resize-width={$width}", $gif], quiet: true);
clearstatcache(true, $gif);
$after = filesize($gif);

io()->writeln(sprintf('%s: %d KB -> %d KB (%d%%)', $gif, $before / 1024, $after / 1024, 100 - $after * 100 / $before));
}
}
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"doctrine/annotations": "^2.0",
"friendsofphp/php-cs-fixer": "^3.17",
"phpstan/phpstan": "^2.1",
"spatie/image-optimizer": "^1.8",
"symfony/asset": "^6.4 || ^7.3 || ^8.0",
"symfony/browser-kit": "^6.4 || ^7.3 || ^8.0",
"symfony/config": "^6.4 || ^7.3 || ^8.0",
Expand Down
83 changes: 0 additions & 83 deletions tests/Command/GifOptimizerCommandTest.php

This file was deleted.

Binary file removed tests/Command/gifs/test.gif
Binary file not shown.
Binary file removed tests/Command/original.gif
Binary file not shown.
30 changes: 30 additions & 0 deletions tests/GifsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
* This file is part of the GifExceptionBundle project.
*
* (c) JoliCode <coucou@jolicode.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Joli\GifExceptionBundle\Tests;

use PHPUnit\Framework\TestCase;

class GifsTest extends TestCase
{
public function testAllGifsAreResized(): void
{
$gifs = glob(__DIR__ . '/../Resources/public/images/*/*.gif');

self::assertNotEmpty($gifs);

foreach ($gifs as $gif) {
[$width] = getimagesize($gif);

self::assertSame(145, $width, basename($gif) . ' is not resized, run `castor optimize`');
}
}
}
Loading
Loading