PHP code example of escapework / resize

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

    

escapework / resize example snippets


use EscapeWork\Resize\Resize;

$resize = new Resize('/path/to/image.jpg');
$resize->setWidth(200)->setHeight(100)->resize(); # ajusta o tamanho automáticamente, mantendo no máximo 200px de largura e/ou 100px de altura

$resize = new Resize('/path/to/image.jpg');
$resize->setWidth(90)->setHeight(90)->crop(); # redimensiona, e depois cropa exatamente 90x90, podendo cortar algumas partes da imagem

$resize = new Resize('/path/to/image.jpg');
$resize->setX(20)->setY(30)->setWidth(300)->setHeight(400)->crop();

$resize = new Resize('/path/to/image.jpg');
$resize->setMinWidth(300)->setMinHeight(500)->resize();

$resize = new Resize('/path/to/other/image.jpg');
$resize->setMinHeight(549)->resize();

$resize = new Resize('/path/to/another/image.jpg');
$resize->setMinWidth(300)->resize();

use EscapeWork\Resize\Upload;

$upload = new Upload($original, $newFile);

use EscapeWork\Resize\Resize;

$dir      = 'img';
$img      = 'original.jpg';
$sizes    = array(
    'mini-' => array(
        'width'  => 80, 
        'height' => 80, 
        'crop'   => true
    ), 
    'thumb-' => array(
        'width'  => 150, 
        'height' => 100, 
        'crop'   => false
    ), 
    'vga-' => array(
        'width'  => 640, 
        'height' => 480, 
        'crop'   => false
    ), 
);

# cria 3 novas imagens [mini-original.jpg], [thumb-original.jpg], [vga-original.jpg], 
# redimensionadas e cropadas conforme as informações do array 
Resize::make( $dir, $img, $sizes );