psliwa / image-optimizer

Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.
MIT License
906 stars 141 forks source link

Fixed the bug that the copied files were not deleted when the optimization failed #77

Closed overtrue closed 2 years ago

overtrue commented 2 years ago

When configured output_filepath_pattern which changed output path, the optimizer copied the file but doesn't deleted it when optimize failed.

today I create a demo with the following code:

require __DIR__ . '/vendor/autoload.php';

$factory = new \ImageOptimizer\OptimizerFactory([
    'output_filepath_pattern' => '%basename%/%filename%_optimized%ext%',
]);
$optimizer = $factory->get();

$filepath = __DIR__ . '/1.png';

$optimizer->optimize($filepath);

it copied two files:

.
├── 1.png
├── 1_optimized.png
├── 1_optimized_optimized.png

Build Status

Thanks.

psliwa commented 2 years ago

Thank you a lot! 👍