PHP code example of futurando-oficial / thumb-generator

1. Go to this page and download the library: Download futurando-oficial/thumb-generator 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/ */

    

futurando-oficial / thumb-generator example snippets



try {
  // Create a new Generator object
  $image = new \Thumb\Generator();

  // Magic! ✨
  $image
    ->fromFile('image.jpg')                     // load image.jpg
    ->autoOrient()                              // adjust orientation based on exif data
    ->resize(320, 200)                          // resize to 320x200 pixels
    ->toFile('new-image.png', 'image/png')      // convert to PNG and save a copy to new-image.png

  // And much more! 💪
} catch(Exception $err) {
  // Handle errors
  echo $err->getMessage();
}


try {
  $image = new \Thumb\Generator('image.jpeg')
  // ...
} catch(Exception $err) {
  echo $err->getMessage();
}


try {
  $image = new \Thumb\Generator('image.jpeg')
  // ...
} catch(Exception $err) {
  if($err->getCode() === $image::ERR_FILE_NOT_FOUND) {
    echo 'File not found!';
  } else {
    echo $err->getMessage();
  }
}

  $string = file_get_contents('image.jpg');