为什么图像优化器导致相同版本而没有增强功能



我安装了作曲家需要Spatie/image-optimizer,但是当我在下面运行示例时,我有两个问题:1-无法通过使用(使用(调用该类。因此,我通过使用Include。

解决了它。

2-解决第一个问题后,代码工作正常,但结果图像是同一图像,没有优化。

include 'Spatie/Imageoptimizer/src/OptimizerChainFactory.php';

require __DIR__.'/autoload.php';
$pathToImage =  "D:/xampp/htdocs/images/vendor/uploads/2.png";
//use SpatieImageOptimizerOptimizerChainFactory;

// Get the image and store the original size
$image = $pathToImage;
$originalSize = filesize($image);
// Optimize updates the existing image
$optimizerChain = OptimizerChainFactory::create();
$optimizerChain->optimize($image);
// Clear stat cache to get the optimized size
clearstatcache();
// Check the optimized size
$optimizedSize = filesize($image);
$percentChange = (1 - $optimizedSize / $originalSize) * 100;
echo sprintf("The image is now %.2f%% smallern", $percentChange);
exit(0);

您能建议我任何解决方案!

我发现了问题的原因,即jpg和optipng工具未安装在窗口中。有什么方法可以在Windows中安装工具并将其链接到插件。

最新更新