PHP code example of lassehaslev / image

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

    

lassehaslev / image example snippets


$baseFolder = '/image';
$cropsFolder = '/image/crops';
$handler = CropHandler::create( $baseFolder, $cropsFolder );

$this->handler
    ->handle( [
        'name'=>'test-image.jpg',
        'width'=>89,
        'height'=>89,
        'resize'=>true,
    ] )
    ->save( 'test-image-89x89-resize.jpg' );

class Adaptor implements CropAdaptorInterface
{
    public function transform( $input, $handler = null )
    {
        return [
            'name'=>$input,
            'width'=>300,
            'height'=>200,
            'resize'=>true,
        ];
    }
}
$baseFolder = '/image';
$cropsFolder = '/image/crops';
$handler = CropHandler::create( $baseFolder, $cropsFolder, new Adaptor );

$this->handler
    ->handle( 'originalFilename.jpg' )
    ->save( 'newFilename' );

use LasseHaslev\Image\Modifiers\ImageModifier;
$modifier = ImageModifier::create( { absolute image path } );

// Crop image function
$modifier->crop( $x1, $y1, $x2, $y2 );

// Crop image to width and height based on fucuspoint
$modifier->cropToFit( $width, $height, $focusPointX = 0, $focusPointY = 0 );

// Resize width and height
$modifier->resize( $width, $height );

// Save the new image
$modifier->save( {absolutePath} );

// Example
$modifier->cropToFit( 300, 300 )
    ->save( '/path/to/image.jpg' );

use LasseHaslev\Image\Handlers\ImageHandler;
$modifier = ImageHandler::create( $filepath );

// Remove the crops
$modifier->removeCrops();

// Save
$modifier->save( $pathOrFilename, $isFullPath = false );
config/app.php