typisttech / image-optimize-command Goto Github PK
View Code? Open in Web Editor NEWEasily optimize images using WP CLI
Home Page: https://typist.tech/articles/easily-optimize-wordpress-images-using-wp-cli-and-some-binaries/
License: MIT License
Easily optimize images using WP CLI
Home Page: https://typist.tech/articles/easily-optimize-wordpress-images-using-wp-cli-and-some-binaries/
License: MIT License
First of all, thank you for this great WP CLI script. Really hope to get it running on our system. Running the following command:
wp image-optimize attachment 12660 --allow-root
On this machine:
Ubuntu 18.04.1 LTS
PHP 7.2.15-0
Which results in this error:
PHP Fatal error: Uncaught Error: Call to undefined method Symfony\Component\Process\Process::fromShellCommandline() in /root/.wp-cli/packages/vendor/spatie/image-optimizer/src/OptimizerChain.php:97
Stack trace:
#0 /root/.wp-cli/packages/vendor/spatie/image-optimizer/src/OptimizerChain.php(77): Spatie\ImageOptimizer\OptimizerChain->applyOptimizer(Object(Spatie\ImageOptimizer\Optimizers\Jpegoptim), Object(Spatie\ImageOptimizer\Image))
#1 /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/Operations/Optimize.php(73): Spatie\ImageOptimizer\OptimizerChain->optimize('/var/www/html/w...')
#2 [internal function]: TypistTech\ImageOptimizeCommand\Operations\Optimize->TypistTech\ImageOptimizeCommand\Operations\{closure}('/var/www/html/w...')
#3 /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/Operations/Optimize.php(74): array_map(Object(Closure), Array)
#4 /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/Operations/AttachmentImages/Optimize.php(104): TypistTech\ImageOptimizeCommand in /root/.wp-cli/packages/vendor/spatie/image-optimizer/src/OptimizerChain.php on line 97
The install went as following:
wp package install typisttech/image-optimize-command:@stable --allow-root
Installing package typisttech/image-optimize-command (@stable)
Updating /root/.wp-cli/packages/composer.json to require the package...
Using Composer to install the package...
---
Loading composer repositories with package information
Updating dependencies
Resolving dependencies through SAT
Looking at all rules.
Something's changed, looking at all rules again (pass #1)
Dependency resolution completed in 5.266 seconds
Analyzed 6338 packages to resolve dependencies
Analyzed 542383 rules to resolve dependencies
Package operations: 7 installs, 0 updates, 0 removals
Installs: symfony/finder:v4.2.3, symfony/polyfill-ctype:v1.10.0, symfony/filesystem:v4.2.3, symfony/process:v4.2.3, psr/log:1.1.0, spatie/image-optimizer:1.1.5, typisttech/image-optimize-command:0.3.1
- Installing symfony/finder (v4.2.3)
- Warning: typisttech/image-optimize-command 0.3.1 requires symfony/finder ^4.1 -> satisfiable by symfony/finder[4.1.x-dev, 4.2.x-dev, 4.3.x-dev, v4.1.0, v4.1.0-BETA1, v4.1.0-BETA2, v4.1.0-BETA3, v4.1.1, v4.1.10, v4.1.11, v4.1.2, v4.1.3, v4.1.4, v4.1.5, v4.1.6, v4.1.7, v4.1.8, v4.1.9, v4.2.0, v4.2.0-BETA1, v4.2.0-BETA2, v4.2.0-RC1, v4.2.1, v4.2.2, v4.2.3].
- Installing symfony/polyfill-ctype (v1.10.0)
- Warning: symfony/filesystem v4.2.3 requires symfony/polyfill-ctype ~1.8 -> satisfiable by symfony/polyfill-ctype[1.11.x-dev, v1.10.0, v1.8.0, v1.9.0].
- Installing symfony/filesystem (v4.2.3)
- Warning: typisttech/image-optimize-command 0.3.1 requires symfony/filesystem ^4.1 -> satisfiable by symfony/filesystem[4.1.x-dev, 4.2.x-dev, 4.3.x-dev, v4.1.0, v4.1.0-BETA1, v4.1.0-BETA2, v4.1.0-BETA3, v4.1.1, v4.1.10, v4.1.11, v4.1.2, v4.1.3, v4.1.4, v4.1.5, v4.1.6, v4.1.7, v4.1.8, v4.1.9, v4.2.0, v4.2.0-BETA1, v4.2.0-BETA2, v4.2.0-RC1, v4.2.1, v4.2.2, v4.2.3].
- Installing symfony/process (v4.2.3)
- Warning: spatie/image-optimizer 1.1.5 requires symfony/process ^4.2 -> satisfiable by symfony/process[4.2.x-dev, 4.3.x-dev, v4.2.0, v4.2.0-BETA1, v4.2.0-BETA2, v4.2.0-RC1, v4.2.1, v4.2.2, v4.2.3].
- Installing psr/log (1.1.0)
- Warning: typisttech/image-optimize-command 0.3.1 requires psr/log ^1.0 -> satisfiable by psr/log[1.0.0, 1.0.1, 1.0.2, 1.1.0, 1.1.x-dev].
- Installing spatie/image-optimizer (1.1.5)
- Warning: typisttech/image-optimize-command 0.3.1 requires spatie/image-optimizer ^1.1.3 -> satisfiable by spatie/image-optimizer[1.1.3, 1.1.4, 1.1.5].
- Installing typisttech/image-optimize-command (0.3.1)
Writing lock file
Generating autoload files
---
Success: Package installed.
Dependabot couldn't resolve your project's dependencies as it couldn't access php-cli-tools.
You can provide additional git credentials in your Dependabot dashboard by clicking into the account menu (in the top right) and selecting 'Config variables'. If you use a custom token for the host github.com
make sure it has read access to this repo, too.
Dependabot couldn't resolve your project's dependencies as it couldn't access phpcodesniffer-composer-installer.
You can provide additional git credentials in your Dependabot dashboard by clicking into the account menu (in the top right) and selecting 'Config variables'. If you use a custom token for the host github.com
make sure it has read access to this repo, too.
Hello,
First of all, thx for this extension that looks awesome.
I have an issue when i try using it and i hope you will be able to help me
wp image-optimize batch
===> Backing up full sized images for 10 attachment(s)
===> Backing up 10 full sized image(s)
Finished
===> Optimizing images for 10 attachment(s)
===> Optimizing images of attachment ID: 9714
===> Optimizing 6 file(s)
PHP Fatal error: Uncaught Error: Call to undefined method Symfony\Component\Process\Process::fromShellCommandline() in /home/forge/.wp-cli/packages/vendor/spatie/image-optimizer/src/OptimizerChain.php:97
Stack trace:
#0 /home/forge/.wp-cli/packages/vendor/spatie/image-optimizer/src/OptimizerChain.php(77): Spatie\ImageOptimizer\OptimizerChain->applyOptimizer(Object(Spatie\ImageOptimizer\Optimizers\Jpegoptim), Object(Spatie\ImageOptimizer\Image))
#1 /home/forge/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/Operations/Optimize.php(73): Spatie\ImageOptimizer\OptimizerChain->optimize('/home/forge/mon...')
#2 [internal function]: TypistTech\ImageOptimizeCommand\Operations\Optimize->TypistTech\ImageOptimizeCommand\Operations{closure}('/home/forge/mon...')
#3 /home/forge/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/Operations/Optimize.php(74): array_map(Object(Closure), Array)
#4 /home/forge/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/Operations/AttachmentImages/Optimize.php(104): T in /home/forge/.wp-cli/packages/vendor/spatie/image-optimizer/src/OptimizerChain.php on line 97
Any idea what i did wrong ?
Thx
I am trying to use this package into wp-cli. When I try to optimize images, I am getting this error.
Fatal error: Uncaught Error: Call to undefined function Spatie\ImageOptimizer\mime_content_type() in /home/xxx/.wp-cli/packages/vendor/spatie/image-optimizer/src/Image.php:22
Stack trace:
#0 /home/xxx/.wp-cli/packages/vendor/spatie/image-optimizer/src/Optimizers/Jpegoptim.php(13): Spatie\ImageOptimizer\Image->mime()
#1 /home/xxx/.wp-cli/packages/vendor/spatie/image-optimizer/src/OptimizerChain.php(83): Spatie\ImageOptimizer\Optimizers\Jpegoptim->canHandle(Object(Spatie\ImageOptimizer\Image))
#2 /home/xxx/.wp-cli/packages/vendor/spatie/image-optimizer/src/OptimizerChain.php(77): Spatie\ImageOptimizer\OptimizerChain->applyOptimizer(Object(Spatie\ImageOptimizer\Optimizers\Jpegoptim), Object(Spatie\ImageOptimizer\Image))
#3 /home/xxx/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/Operations/Optimize.php(73): Spatie\ImageOptimizer\OptimizerChain->optimize('/home/xxx/...')
#4 [internal function]: TypistTech\ImageOptimizeCommand\Operations\Optimize->TypistTech\ImageOptimizeCommand\Ope in /home/xxx/.wp-cli/packages/vendor/spatie/image-optimizer/src/Image.php on line 22
is there anything missing during installation?
My command is::
wp image-optimize find /home/xxx/public_html --extensions=gif,jpeg,jpg,png,svg
Thanks in advance.
Hi, I wanted to test your image optimization script, but I ran into a problem.
My server is running on Debian 11.
PHP Ver.: 7.4
I have installed WP Cli.
I also installed all the necessary packages:
$ sudo apt-get install jpegoptim
$ sudo apt-get install optipng
$ sudo apt-get install pngquant
$ sudo apt-get install gifsicle
When testing from the console with the command wp --allow-root image-optimize batch --limit=10
I get an error:
root@1110759-ce36154:/usr/local/lsws/SchoolTop/html# wp --allow-root image-optimize batch --limit=10
===> Backing up full sized images for 1 attachment(s)
===> Backing up 1 full sized image(s)
Success: Backed up full sized image - /usr/local/lsws/SchoolTop/html/wp-content/uploads/2022/11/2-2.jpg
Finished
===> Optimizing images for 1 attachment(s)
===> Optimizing images of attachment ID: 11
===> Optimizing 10 file(s)
PHP Fatal error: Uncaught Error: Call to undefined method Symfony\Component\Process\Process::fromShellCommandline() in /root/.wp-cli/packages/vendor/spatie/image-optimizer/src/OptimizerChain.php:97
Stack trace:
#0 /root/.wp-cli/packages/vendor/spatie/image-optimizer/src/OptimizerChain.php(77): Spatie\ImageOptimizer\OptimizerChain->applyOptimizer()
#1 /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/Operations/Optimize.php(71): Spatie\ImageOptimizer\OptimizerChain->optimize()
#2 [internal function]: TypistTech\ImageOptimizeCommand\Operations\Optimize->TypistTech\ImageOptimizeCommand\Operations\{closure}()
#3 /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/Operations/Optimize.php(69): array_map()
#4 /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/Operations/AttachmentImages/Optimize.php(101): TypistTech\ImageOptimizeCommand\Operations\Optimize->execute()
#5 /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/Operations/AttachmentImages/Optimize.php(64): in /root/.wp-cli/packages/vendor/spatie/image-optimizer/src/OptimizerChain.php on line 97
Fatal error: Uncaught Error: Call to undefined method Symfony\Component\Process\Process::fromShellCommandline() in /root/.wp-cli/packages/vendor/spatie/image-optimizer/src/OptimizerChain.php:97
Stack trace:
#0 /root/.wp-cli/packages/vendor/spatie/image-optimizer/src/OptimizerChain.php(77): Spatie\ImageOptimizer\OptimizerChain->applyOptimizer()
#1 /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/Operations/Optimize.php(71): Spatie\ImageOptimizer\OptimizerChain->optimize()
#2 [internal function]: TypistTech\ImageOptimizeCommand\Operations\Optimize->TypistTech\ImageOptimizeCommand\Operations\{closure}()
#3 /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/Operations/Optimize.php(69): array_map()
#4 /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/Operations/AttachmentImages/Optimize.php(101): TypistTech\ImageOptimizeCommand\Operations\Optimize->execute()
#5 /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/Operations/AttachmentImages/Optimize.php(64): in /root/.wp-cli/packages/vendor/spatie/image-optimizer/src/OptimizerChain.php on line 97
Error: A critical error has occurred on the site.Learn more about solving problems with WordPress. A critical error has occurred on the site.
The backup file was successfully created, but then, alas, the optimization failed
Do you have any ideas how to solve this problem?
I'm very new to Laravel. Initially, my project was working perfectly, few weeks now uploaded images refused to display, all uploaded images are broken. When I checked my Laravel Log here is what I get
production.ERROR: Call to undefined function Illuminate\Filesystem\finfo_file() {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Call to undefined function Illuminate\Filesystem\finfo_file() at /home/crescen1/crescentlaravel/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:299)
Here is the code I have in my filesystem.php: line 299
`/**
/**
Hi,
When installing this tool via "wp package install typisttech/image-optimize-command:@stable" I get this error message:
Error: curl error 60 while downloading https://wp-cli.org/package-index/packages.json: SSL certificate problem: certificate has expired
Please update your certificate and/or provide a workaround for install.
Have a great day,
Richard
Hi there,
I've been using this tool a while ago with great success, however I can't deploy it out of the box at the moment.
My server has several PHP versions installed, so I can choose the one I need for each or my Vhost. The default php version is 8.1, but one of my wp site is still running on php 7.4.
when it try to deploy this tool on this wp site I get this error message :
Dependency resolution completed in 0.001 seconds
Your requirements could not be resolved to an installable set of packages.
Problem 1
- typisttech/image-optimize-command[0.1.0, 0.1.1, 0.1.2, 0.2.0, 0.3.0] require php ^7.1 -> your php version (8.1.14) does not satisfy that requirement.
- typisttech/image-optimize-command[0.3.1, 0.4.0, 0.4.1, 0.4.2] require php ^7.2 -> your php version (8.1.14) does not satisfy that requirement.
- Root composer.json requires typisttech/image-optimize-command @stable -> satisfiable by typisttech/image-optimize-command[0.1.0, 0.1.1, 0.1.2, 0.2.0, 0.3.0, 0.3.1, 0.4.0, 0.4.1, 0.4.2].
Running update with --no-dev does not mean require-dev is ignored, it just means the packages will not be installed. If dev requirements are blocking the update you have to resolve those problems.
---
Error: Package installation failed (Composer return code 2).
Reverted composer.json.
As I understand your tool check for my php version, and get the default php version the serve use, not the php version that is used by the vhost i'm deploying it into.
Plus the error message says it should be above 7.2, not the it could not be 8+
I guess I can tweak your code to change the requirement but, isn't there any classier way to deploy it for a site in the above context ?
Thank's in advance for your feedback
when cimg/php
includes phpdbg, CircleCI-Public/cimg-php#97 (comment)
Dependabot couldn't resolve your project's dependencies as it couldn't access log.
You can provide additional git credentials in your Dependabot dashboard by clicking into the account menu (in the top right) and selecting 'Config variables'. If you use a custom token for the host github.com
make sure it has read access to this repo, too.
Hi,
Thank you for your package! However, I've encountered an Uncaught TypeError
during running the command. Could you please take a look? Thank you!
PHP Warning: Use of undefined constant CUSTOM_USER_TABLE - assumed 'CUSTOM_USER_TABLE' (this will throw an Error in a future version of PHP) in phar:///usr/local/bin/wp/php/WP_CLI/Runner.php(1138) : eval()'d code on line 84
PHP Warning: Use of undefined constant CUSTOM_USER_META_TABLE - assumed 'CUSTOM_USER_META_TABLE' (this will throw an Error in a future version of PHP) in phar:///usr/local/bin/wp/php/WP_CLI/Runner.php(1138) : eval()'d code on line 85
PHP Fatal error: Uncaught TypeError: Argument 1 passed to TypistTech\ImageOptimizeCommand\AttachmentRepository::take() must be of the type integer, string given, called in /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/ImageOptimizeCommand.php on line 30 and defined in /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/AttachmentRepository.php:20
Stack trace:
#0 /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/ImageOptimizeCommand.php(30): TypistTech\ImageOptimizeCommand\AttachmentRepository::take('10')
#1 [internal function]: TypistTech\ImageOptimizeCommand\ImageOptimizeCommand->run(Array, Array)
#2 phar:///usr/local/bin/wp/php/WP_CLI/Dispatcher/CommandFactory.php(89): call_user_func(Array, Array, Array)
#3 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}(Array, Array)
#4 phar:///usr/local/bin/wp/php/WP_CLI/Dispatcher/Subcommand.php(425): call_user_func(Object(Closure), Array, Array)
#5 phar:///usr/local/bin/wp/php/WP_CLI/Runner.php(35 in /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/AttachmentRepository.php on line 20
Fatal error: Uncaught TypeError: Argument 1 passed to TypistTech\ImageOptimizeCommand\AttachmentRepository::take() must be of the type integer, string given, called in /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/ImageOptimizeCommand.php on line 30 and defined in /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/AttachmentRepository.php:20
Stack trace:
#0 /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/ImageOptimizeCommand.php(30): TypistTech\ImageOptimizeCommand\AttachmentRepository::take('10')
#1 [internal function]: TypistTech\ImageOptimizeCommand\ImageOptimizeCommand->run(Array, Array)
#2 phar:///usr/local/bin/wp/php/WP_CLI/Dispatcher/CommandFactory.php(89): call_user_func(Array, Array, Array)
#3 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}(Array, Array)
#4 phar:///usr/local/bin/wp/php/WP_CLI/Dispatcher/Subcommand.php(425): call_user_func(Object(Closure), Array, Array)
#5 phar:///usr/local/bin/wp/php/WP_CLI/Runner.php(35 in /root/.wp-cli/packages/vendor/typisttech/image-optimize-command/src/AttachmentRepository.php on line 20
My PHP version is 7.2.4 & WP CLI version is 1.5.1
Hi,
It's possible to skip the backup file when executing the 'wp image-optimize attachment' command?
Dependabot couldn't resolve your project's dependencies as it couldn't access Codeception.
You can provide additional git credentials in your Dependabot dashboard by clicking into the account menu (in the top right) and selecting 'Config variables'. If you use a custom token for the host github.com
make sure it has read access to this repo, too.
Hi there,
I have a new error.
PHP Fatal error: Uncaught Symfony\Component\Process\Exception\RuntimeException: The process has been signaled with signal "11". in phar:///usr/local/bin/wp/vendor/symfony/process/Process.php:366
At beginning the script was working well but since 2 days I get this error. I tried to empty composer cache, restart server, but it didn't work.
Do you know where this issue might comes from?
Many thanks in advance.
Dependabot couldn't resolve your project's dependencies as it couldn't access event-dispatcher.
You can provide additional git credentials in your Dependabot dashboard by clicking into the account menu (in the top right) and selecting 'Config variables'. If you use a custom token for the host github.com
make sure it has read access to this repo, too.
Hi
Will this work on multisite, and if yes, what id is references when using e.g. "wp image-optimize restore 123" ?
Best regards
Kristian
Hi,
Is there are any way to delete backup images...
I used this command to compress images
$ wp media regenerate $ wp image-optimize batch --limit=9999999
Dependabot couldn't resolve your project's dependencies as it couldn't access phpcodesniffer-composer-installer.
You can provide additional git credentials in your Dependabot dashboard by clicking into the account menu (in the top right) and selecting 'Config variables'. If you use a custom token for the host github.com
make sure it has read access to this repo, too.
Dependabot couldn't resolve your project's dependencies as it couldn't access mockery.
You can provide additional git credentials in your Dependabot dashboard by clicking into the account menu (in the top right) and selecting 'Config variables'. If you use a custom token for the host github.com
make sure it has read access to this repo, too.
Dependabot couldn't resolve your project's dependencies as it couldn't access phpunit-wrapper.
You can provide additional git credentials in your Dependabot dashboard by clicking into the account menu (in the top right) and selecting 'Config variables'. If you use a custom token for the host github.com
make sure it has read access to this repo, too.
Dependabot couldn't resolve your project's dependencies as it couldn't access php-cli-tools.
You can provide additional git credentials in your Dependabot dashboard by clicking into the account menu (in the top right) and selecting 'Config variables'. If you use a custom token for the host github.com
make sure it has read access to this repo, too.
Hi!
Thank you for your work: this command is awesome and it works like a charms.
We have some issue with the latest update of wp-cli: when we try to install your extension we have some errors like:
Problem 1 - Conclusion: remove wp-cli/wp-cli 2.0.1 - typisttech/image-optimize-command 0.1.0 requires wp-cli/wp-cli ^1.4.1 -> satisfiable by wp-cli/wp-cli[v1.4.1, v1.5.0, v1.5.1]. - typisttech/image-optimize-command 0.1.1 requires wp-cli/wp-cli ^1.4.1 -> satisfiable by wp-cli/wp-cli[v1.4.1, v1.5.0, v1.5.1]. - typisttech/image-optimize-command 0.1.2 requires wp-cli/wp-cli ^1.4.1 -> satisfiable by wp-cli/wp-cli[v1.4.1, v1.5.0, v1.5.1]. - Can only install one of: wp-cli/wp-cli[v2.0.1, v1.4.1]. - Can only install one of: wp-cli/wp-cli[v2.0.1, v1.5.0]. - Can only install one of: wp-cli/wp-cli[v2.0.1, v1.5.1]. - Installation request for wp-cli/wp-cli 2.0.1 -> satisfiable by wp-cli/wp-cli[2.0.1]. - Installation request for typisttech/image-optimize-command @stable -> satisfiable by typisttech/image-optimize-command[0.1.0, 0.1.1, 0.1.2]. Running update with --no-dev does not mean require-dev is ignored, it just means the packages will not be installed. If dev requirements are blocking the update you have to resolve those problems.
How we can bypass this error?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.