lciolecki/php-image-optimizer

Binary problem

Opened this issue · 1 comments

I have error like this

Fatal error: Uncaught exception 'Exception' with message 'Unable to locate binary file' in C:\work\htdocs\pbot\vendor\bensquire\php-image-optim\src\PHPImageOptim\Tools\Common.php:26 Stack trace: #0 C:\work\htdocs\pbot\vendor\lciolecki\php-image-optimizer\src\Extlib\ImageOptimizer.php(75): PHPImageOptim\Tools\Common->setBinaryPath('/usr/bin/jpegop...') #1 C:\work\htdocs\pbot\test.php(9): Extlib\ImageOptimizer->__construct(Array) #2 {main} thrown in C:\work\htdocs\pbot\vendor\bensquire\php-image-optim\src\PHPImageOptim\Tools\Common.php on line 26

my code

<?php

require_once("vendor/autoload.php");

$optimizer = new \Extlib\ImageOptimizer(array(
    \Extlib\ImageOptimizer::OPTIMIZER_OPTIPNG => '/usr/bin/optipng',  //your_path
    \Extlib\ImageOptimizer::OPTIMIZER_JPEGOPTIM => '/usr/bin/jpegoptim', //your_path
    \Extlib\ImageOptimizer::OPTIMIZER_GIFSICLE => '/usr/bin/gifsicle' //your_path
));

$optimizer->optimize("image.png"); //return true
$optimizer->optimize("image.jpg"); //return true
$optimizer->optimize("image.gif"); //return true
$optimizer->optimize("file.txt"); //return false

I see that you use Windows.. I don't test this case and I don't know whether there are exists solutions optipng/jpgeoptim/gifsicle for Windows.. You can try install some of this app for windwows and set for example:

$optimizer = new \Extlib\ImageOptimizer(array(
\Extlib\ImageOptimizer::OPTIMIZER_OPTIPNG => 'C:\optipng\optipng.exe'
));

But really I don't know whether this would be works..