1. Go to this page and download the library: Download minipng/laravel-minipng 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/ */
use MiniPNG\LaravelMiniPNG\Facades\MiniPNG;
// Compress an image
$result = MiniPNG::compressImage('https://example.com/image.jpg');
// Convert image format
$result = MiniPNG::convertImage('https://example.com/image.jpg', 'webp', 90);
// Compress PDF
$result = MiniPNG::compressPdf('https://example.com/document.pdf');
// Convert PDF to images
$result = MiniPNG::convertPdfToImages('https://example.com/document.pdf', 'high', 'jpg');
// Get user profile
$profile = MiniPNG::getProfile();
use MiniPNG\LaravelMiniPNG\Contracts\MiniPNGInterface;
class ImageController extends Controller
{
public function __construct(private MiniPNGInterface $minipng)
{
}
public function compress(Request $request)
{
$result = $this->minipng->compressImage($request->input('image_url'));
return response()->json($result);
}
}