PHP code example of scrapify-dev / image-tool

1. Go to this page and download the library: Download scrapify-dev/image-tool 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/ */

    

scrapify-dev / image-tool example snippets


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),
]);

use Scrapify\ImageTools\CompressImage;

$compressor = new CompressImage();
$result = $compressor->compress($request->file('image_file'));

use Scrapify\ImageTools\ConvertImage;

$converter = new ConvertImage();
$result = $converter->convert($request->file('image_file'), 'webp');

use Scrapify\ImageTools\CropImage;

$cropper = new CropImage();
$result = $cropper->crop($file, [
    'x' => 100,
    'y' => 50,
    'width' => 200,
    'height' => 150
]);

use Scrapify\ImageTools\ResizeImage;

$resizer = new ResizeImage();
$result = $resizer->resize($file, 500, 300);

use Scrapify\ImageTools\RotateImage;

$rotator = new RotateImage();
$result = $rotator->rotate($file, 90);

use Scrapify\ImageTools\HtmlToImage;

$htmlToImage = new HtmlToImage();
$result = $htmlToImage->convert('https://example.com', 'png');

if ($result['success']) {
    echo "Image saved at: " . $result['url'];
}

private $apiKey = 'YOUR_SCREENSHOTLAYER_API_KEY';

use Scrapify\ImageTools\UpscaleImage;

$upscaler = new UpscaleImage();
$result = $upscaler->upscale($file, 2.0);

use Scrapify\ImageTools\RemoveBG;

$removeBG = new RemoveBG();
$result = $removeBG->remove($request->file('image_file'));

$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);

use Scrapify\ImageTools\ImageToText;

$imageTool = new ImageToText($file);
$text = $imageTool->process();