1. Go to this page and download the library: Download io-developer/php-thumbnails 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/ */
io-developer / php-thumbnails example snippets
class MyImageType
{
const ORIGINAL = "";
const FULLSIZE = "fullsize";
const WIDE = "wide";
const SQUARE = "square";
}
use iodev\Lib\Thumbnails\Thumbnailer;
class MyImage
{
/** @var Thumbnailer */
private static $_thumbnailer = null;
/**
* @return Thumbnailer
*/
public static function getThumbnailer()
{
if (self::$_thumbnailer == null) {
self::$_thumbnailer = MyImageFactory::createThumbnailer();
}
return self::$_thumbnailer;
}
/**
* @param string $path
*/
public function __construct( $path )
{
$m = new MyImage();
$m->path = $path;
return $m;
}
/** @var string */
public $path = "";
/**
* @return string
*/
public function toUri( $imageType="" )
{
return self::getThumbnailer()
->resolveLocationByName($this->path, $imageType);
}
/**
* @return string
*/
public function toFullsizeUri()
{
return $this->toUri(MyImageType::FULLSIZE);
}
/**
* @return string
*/
public function toWideUri()
{
return $this->toUri(MyImageType::WIDE);
}
/**
* @return string
*/
public function toSquareUri()
{
return $this->toUri(MyImageType::SQUARE);
}
}
// For example: you need to thumbnail main image of some article. So content ID it's article ID :)
$contentId = 123;
$inputName = "image-file-form-input-name";
$areaSet = null;
$overlayWatermarks = true;
$thumbnailer = MyImage::getThumbnailer();
$result = $thumbnailer->thumbnailFormInput($contentId, $inputName, $areaSet, $overlayWatermarks);
// thumbnailed image path to store to somewhere
$path = $result->getPrimaryPath();
$myThumbnailedImage = new MyImage($path);