Laravel package for MiniPNG API integration - Image and PDF processing
minipng/laravel-minipng is a Laravel package for laravel package for minipng api integration - image and pdf processing.
It currently has 1 GitHub stars and 1 downloads on Packagist (latest version 1.0.0).
Install it with composer require minipng/laravel-minipng.
Discover more Laravel packages by minipng
or browse all Laravel packages to compare alternatives.
Last updated
Laravel package for integrating with MiniPNG API - Image and PDF processing services.
Version: 1.0.0
Release Date: June 29, 2025
To use this package, you need a MiniPNG API token:
Install the package via Composer:
composer require minipng/laravel-minipng
Publish the configuration file:
php artisan vendor:publish --tag=minipng-config
Add your MiniPNG API key to your .env file:
MINIPNG_API_KEY=your_api_key_here
MINIPNG_BASE_URL=https://minipng.com
The configuration file config/minipng.php contains the following options:
return [
'api_key' => env('MINIPNG_API_KEY', ''),
'base_url' => env('MINIPNG_BASE_URL', 'https://minipng.com'),
'api_version' => env('MINIPNG_API_VERSION', 'v1'),
'timeout' => env('MINIPNG_TIMEOUT', 30),
'retry_attempts' => env('MINIPNG_RETRY_ATTEMPTS', 3),
'default_image_quality' => env('MINIPNG_DEFAULT_IMAGE_QUALITY', 85),
'default_pdf_images_quality' => env('MINIPNG_DEFAULT_PDF_IMAGES_QUALITY', 'medium'),
'default_pdf_images_format' => env('MINIPNG_DEFAULT_PDF_IMAGES_FORMAT', 'png'),
];
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);
}
}
$minipng = app('minipng');
$result = $minipng->compressImage('https://example.com/image.jpg');
Compress an image file to reduce its size while maintaining quality.
$result = MiniPNG::compressImage('https://example.com/image.jpg');
Convert an image to a different format.
// Convert to WebP with 90% quality
$result = MiniPNG::convertImage('https://example.com/image.jpg', 'webp', 90);
// Convert to PNG with default quality
$result = MiniPNG::convertImage('https://example.com/image.jpg', 'png');
Supported formats: png, jpg, jpeg, webp, gif
Compress a PDF file to reduce its size while maintaining quality.
$result = MiniPNG::compressPdf('https://example.com/document.pdf');
Convert a PDF document to a set of images (one per page).
// Convert to high-quality JPG images
$result = MiniPNG::convertPdfToImages('https://example.com/document.pdf', 'high', 'jpg');
// Convert to medium-quality PNG images (default)
$result = MiniPNG::convertPdfToImages('https://example.com/document.pdf');
Quality options: low, medium, high
Format options: png, jpg
Get user profile and API usage information.
$profile = MiniPNG::getProfile();
{
"success": true,
"output_ext": "jpg",
"size_before": 1024000,
"size_after": 512000,
"compression_percentage": "50%",
"download": "https://example.com/compressed/image.jpg"
}
{
"error": "Invalid source URL provided",
"message": "The provided URL is not accessible or invalid"
}
The package throws MiniPNGException for API errors:
use MiniPNG\LaravelMiniPNG\Exceptions\MiniPNGException;
try {
$result = MiniPNG::compressImage('https://example.com/image.jpg');
} catch (MiniPNGException $e) {
// Handle API errors
Log::error('MiniPNG API Error: ' . $e->getMessage());
}
<?php
namespace App\Http\Controllers;
use MiniPNG\LaravelMiniPNG\Facades\MiniPNG;
use MiniPNG\LaravelMiniPNG\Exceptions\MiniPNGException;
use Illuminate\Http\Request;
class ImageController extends Controller
{
public function compress(Request $request)
{
$request->validate([
'image_url' => 'required|url',
]);
try {
$result = MiniPNG::compressImage($request->input('image_url'));
return response()->json([
'success' => true,
'data' => $result,
]);
} catch (MiniPNGException $e) {
return response()->json([
'success' => false,
'message' => $e->getMessage(),
], 400);
}
}
public function convert(Request $request)
{
$request->validate([
'image_url' => 'required|url',
'format' => 'required|in:png,jpg,jpeg,webp,gif',
'quality' => 'nullable|integer|min:1|max:100',
]);
try {
$result = MiniPNG::convertImage(
$request->input('image_url'),
$request->input('format'),
$request->input('quality')
);
return response()->json([
'success' => true,
'data' => $result,
]);
} catch (MiniPNGException $e) {
return response()->json([
'success' => false,
'message' => $e->getMessage(),
], 400);
}
}
}
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use MiniPNG\LaravelMiniPNG\Facades\MiniPNG;
class CompressImage extends Command
{
protected $signature = 'image:compress {url}';
protected $description = 'Compress an image using MiniPNG API';
public function handle()
{
$url = $this->argument('url');
$this->info("Compressing image: {$url}");
try {
$result = MiniPNG::compressImage($url);
$this->info("Compression successful!");
$this->table(['Metric', 'Value'], [
['Original Size', $result['size_before'] . ' bytes'],
['Compressed Size', $result['size_after'] . ' bytes'],
['Compression', $result['compression_percentage']],
['Download URL', $result['download']],
]);
} catch (\Exception $e) {
$this->error("Compression failed: " . $e->getMessage());
}
}
}
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
For support, please contact: [email protected]