PHP code example of kenura / imagick

1. Go to this page and download the library: Download kenura/imagick 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/ */

    

kenura / imagick example snippets




enura\Imagick\ImageProcessor;

$processor = new ImageProcessor();

// Resize an image
$processor->resizeImage('input.jpg', 'output.jpg', 800, 600);

// Compress to ~100KB
$processor->compressToJpg('large.jpg', 'compressed.jpg', 100);

// Add watermark
$processor->addWatermark('photo.jpg', 'watermarked.jpg', 'logo.png', 'bottom-right', 10);

// Convert to WebP
$processor->convertToWebP('photo.jpg', 'photo.webp', 85);

$processor->resizeImage($inputPath, $outputPath, $width, $height);

$processor->compressToJpg($inputPath, $outputPath, $targetSizeKB, $quality = 80);

$processor->addWatermark($inputPath, $outputPath, $watermarkPath, $position = 'center', $scale = 10);

$processor->addOpacity($inputPath, $outputPath, $opacityPercent);

$processor->convertToWebP($inputPath, $outputPath, $quality = 80);

$processor->resizeAndCompress($inputPath, $outputPath, $width, $height, $targetSizeKB);

$processor->resizeWatermarkAndCompress(
    $inputPath, 
    $outputPath, 
    $width, 
    $height, 
    $watermarkPath, 
    $position, 
    $scale, 
    $scale, 
    $targetSizeKB
);
bash
# Resize example
php test/resize.php

# Compression example
php test/compress.php

# Watermark example
php test/watermark.php

# WebP conversion example
php test/webp.php

# Opacity example
php test/opacity.php