scrapify-dev / image-tool
Laravel package for image tools like Compress, Resize, Rotate.
Requires
- php: ^8.2
- barryvdh/laravel-dompdf: ^3.1
- illuminate/support: ^9.0|^10.0|^11.0|^12.0
- intervention/image: ^3.0
- spatie/browsershot: ^5.0
- spatie/pdf-to-image: ^1.2
- thiagoalessio/tesseract_ocr: ^2.13
README
📸 Scrapify Image Tools Library
A Laravel package for powerful image processing including compression, conversion, cropping, resizing, rotation, HTML-to-image conversion, upscaling, background removal (remove.bg API), and OCR (image-to-text).
This library wraps several industry-standard packages into an easy-to-use Laravel API.
📦 Installation
composer require scrapify-dev/image-tools
⚙️ Requirements
-
PHP:
^8.2
-
Laravel:
^9.0
|^10.0
|^11.0
|^12.0
-
Dependencies:
intervention/image:^3.0
barryvdh/laravel-dompdf:^3.1
spatie/browsershot:^5.0
spatie/pdf-to-image:^1.2
thiagoalessio/tesseract_ocr:^2.13
illuminate/support
(as per Laravel version)
🚀 Quick Start
use Scrapify\ImageTools\CompressImage; $compressor = new CompressImage(); $result = $compressor->compress($request->file('image_file')); return response()->json([ 'filename' => $result['filename'], 'url' => $result['url'], 'size_kb' => round($result['size'] / 1024, 2), ]);
📑 Table of Contents
- Compress Image
- Convert Image
- Crop Image
- Resize Image
- Rotate Image
- HTML to Image
- Upscale Image
- Remove Background
- Image to Text (OCR)
1️⃣ Compress Image
Reduces file size with minimal quality loss. PNGs are auto-converted to JPG for better compression.
use Scrapify\ImageTools\CompressImage; $compressor = new CompressImage(); $result = $compressor->compress($request->file('image_file'));
2️⃣ Convert Image
Supported formats: jpg
, png
, gif
, webp
, avif
, pdf
use Scrapify\ImageTools\ConvertImage; $converter = new ConvertImage(); $result = $converter->convert($request->file('image_file'), 'webp');
3️⃣ Crop Image
use Scrapify\ImageTools\CropImage; $cropper = new CropImage(); $result = $cropper->crop($file, [ 'x' => 100, 'y' => 50, 'width' => 200, 'height' => 150 ]);
4️⃣ Resize Image
use Scrapify\ImageTools\ResizeImage; $resizer = new ResizeImage(); $result = $resizer->resize($file, 500, 300);
5️⃣ Rotate Image
use Scrapify\ImageTools\RotateImage; $rotator = new RotateImage(); $result = $rotator->rotate($file, 90);
6️⃣ HTML to Image
Converts a live HTML page or URL to an image using ScreenshotLayer API (no Puppeteer required).
use Scrapify\ImageTools\HtmlToImage; $htmlToImage = new HtmlToImage(); $result = $htmlToImage->convert('https://example.com', 'png'); if ($result['success']) { echo "Image saved at: " . $result['url']; }
Example Class Implementation:
private $apiKey = 'YOUR_SCREENSHOTLAYER_API_KEY';
Make sure to replace with your actual API key.
7️⃣ Upscale Image
use Scrapify\ImageTools\UpscaleImage; $upscaler = new UpscaleImage(); $result = $upscaler->upscale($file, 2.0);
8️⃣ Remove Background (remove.bg API)
Removes the background of an image using the remove.bg API.
use Scrapify\ImageTools\RemoveBG; $removeBG = new RemoveBG(); $result = $removeBG->remove($request->file('image_file'));
Example Class Implementation:
$apiKey = 'YOUR_REMOVE_BG_API_KEY'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.remove.bg/v1.0/removebg"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); $postFields = [ 'image_file' => new \CURLFile( $imageFile->getRealPath(), $imageFile->getMimeType(), $imageFile->getClientOriginalName() ), 'size' => 'auto', ]; curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "X-Api-Key: $apiKey" ]); $result = curl_exec($ch); if (curl_errno($ch)) { throw new Exception("cURL error: " . curl_error($ch)); } curl_close($ch);
9️⃣ Image to Text (OCR)
Extracts text from an image using thiagoalessio/tesseract_ocr
.
No need to install Tesseract manually — it runs directly from PHP.
use Scrapify\ImageTools\ImageToText; $imageTool = new ImageToText($file); $text = $imageTool->process();