PHP code example of zepekegno / resize-image

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

    

zepekegno / resize-image example snippets



//Resize an image

// Example with png
$source = 'image.png';

$resizeImage = new zepekegno\Resize($source,50,50);


/**
 * If file exist a copy of this file will be created with suffix cpr
*/
$resizeImage->make(target:'tmp/final',quality:9);

//if delete is true will delete this file and create a new file
$resizeImage->make(target:'tmp/final',quality:9,delete:true);

// Example with Gif

$source = 'image.gif';

$resizeImage = new zepekegno\Resize($source,50,50);

/**
 * If file exist a copy of this file will be created with suffix cpr
*/
$resizeImage->make('tmp/final');

//if delete is true will delete this file and create a new file
$resizeImage->make(target:'tmp/final',delete:true);

//Convert an image to other format 
/**
 * convert image png to jpeg
 * Return the path of image
*/
$source = 'image.png';
$convertImage = new zepekegno\Resize(source:$source,height:50,width:50);
$convertImage->convert(type:'jpeg',target:'tmp/final',quality:100,isResizable:false);

/**
 * Convert png to jpeg and resize it
 * if we want to resize, past isResizable to true
 * Return the path of image
*/
$source = 'image.png';
$convertImage = new zepekegno\Resize(source:$source,height:50,width:50);
$img = $convertImage->convert(type:'jpeg',target:'tmp/final',quality:100,isResizable:true);

// Generate image
$image = "<img src=\"{$img}\"/>";