1. Go to this page and download the library: Download megaoptim/megaoptim-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
megaoptim / megaoptim-php example snippets
use MegaOptim\Optimizer;
$megaoptim = new Optimizer('your-api-key');
$response = $megaoptim->run( '/path/to/file.jpg', array( 'compression' => Optimizer::COMPRESSION_INTELLIGENT ) );
use MegaOptim\Optimizer;
$megaoptim = new Optimizer('your-api-key');
$response = $megaoptim->run( 'http://yoursite.com/some_image.jpg', array( 'compression' => Optimizer::COMPRESSION_INTELLIGENT ) );
$files = $response->getOptimizedFiles();
foreach($files as $file) {
// Do something
}
if( !empty($files) ) {
// Note: Thise are for demonstration purposes, you don't have to use it like this.
// Overwrite
$files[0]->saveOverwrite();
// Or save as other file
$files[0]->saveAsFile('/path/to/other/file.jpg');
// Or save in some other dir with the original name
$files[0]->saveToDir('/path/to/other');
}
composer
public function run($resource, $args = array())
$response
$response->isSuccessful()
$response->isError()
$response->getErrors()
array
$response->getOptimizedFiles()
$file->getFileName()
$file->getOptimizedSize()
$file->getSavedBytes()
$file->getSavedPercent()
$file->getUrl()
$file->getWebP()
$file->saveOverwrite()
$file->saveAsFile( $file_path )
$file->saveToDir( $dir_path )
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.