Download the PHP package megaoptim/megaoptim-php without Composer
On this page you can find all versions of the php package megaoptim/megaoptim-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download megaoptim/megaoptim-php
More information about megaoptim/megaoptim-php
Files in megaoptim/megaoptim-php
Package megaoptim-php
Short Description PHP sdk to utilize the MegaOptim.com image optimization API
License MIT
Informations about the package megaoptim-php
MegaOptim
MegaOptim provides REST based APIs for optimizing images while keeping them almost identical to the original image but significantly reducing the image size using its advanced algorithms.
The end result is to satisfy the pagespeed requirements, fast website load, less space usage, etc.
This library can be installed with composer or without composer and can be used in differet use cases such as optimizing your library, optimizing the uploaded image on the go, etc.
Requirements
- Api Key from MegaOptim.com
Installation
Composer
You can install it with composer
Without Composer
This is not recommended way. But you can require the loadnoncomposer.php
file that will load the library without composer.
How to Use
This library has a class that will be used in 99% of the usecases and it is called and the method is the method used for optimization. Its definition is as follows:
-
string|array
The resources path, can be: Single image path OR Single URL OR multiple local paths OR multiple urls in array. But not mixed array of urls and paths.
-
array
The parameters that describe how the optimization is going to be. It has few properties:-
- 1 OR 0
-
- Numeric px value
-
- Numeric px value
-
- 1 OR 0
-
- intelligent (default), ultra OR lossless
-
- 1 OR 0 (generate or don't generate webp)
The parameter is not required and the defaults are as follows:
To optimize single image call the method on some given parameters just like the following examples:
Single Local File
Single URL
Multiple Files ( up to 5 )
Multiple URLs ( up to 5 )
Handling Response
Once we run the optimization with run()
method we have the instance of MegaOptim\Http\Response
which contains all the response variables and array of optimized image objects.
The contents of the methods are as follows:
-
- Returns boolean to determine if the optimization was successful.
-
- Returns boolean to determine if the optimization was not successful.
-
- Returns with errors.
-
- Returns array of from the class
To get the optimized image objects and further process them we can use the getOptimizedFiles()
method which will return array as mentioned above:
We have the following properties and methods available to use for each optimized image object:
-
- Returns the original file name.
-
- Returns the new size in bytes.
-
- Returns the total saved bytes.
-
- Returns the total saved space in percentage.
-
- Returns the optimized image url. You need to download and store it on your server because it will be removed after 1 hour from MegaOptim server
-
- Returns NULL if there is no webp version available or ResultWebP instance for the webp version of this file.
To save the optimized images locally we have three methods available:
-
- Overwrites the local file with the new optimized file. Only available when local files are being optimized, not URLs.
-
- Saves the optimized file in the specified file path. If the result directory doesn't exist it attempts to create it recursively.
-
- Saves the optimized file in the specified directory path. If the result directory doesn't exist it attempts to create it recursively.
TODO
- Test library on different Operating Systems such as Windows.
Development
If you found a bug or want to contribute to the script feel free to create pull requests to make it even better!