Introduction
Providing some functions for processing image (especially image crop)
Fegg\Tool\Trim resizes and crops JPEG, GIF and PNG images with the GD extension. JPEG images are rotated according to their Exif orientation.
How to use
Import Fegg\Tool\Trim and create it with new. Set the source image and the output path with Trim::setImage, resize it with one of the resize* methods, then save it with Trim::create.
<?php
namespace Site\Controller;
defined('FEGG_CORE_DIR') || exit;
use Fegg\Tool\Trim;
class Thumbnail extends Controller
{
public function index()
{
$trim = new Trim();
$trim->setImage('path/to/image.jpg', 'path/to/thumbnail/300_300.jpg');
$trim->resizeTrim(300, 300, 'm');
$trim->create();
// Output the saved image to the browser
$trim->view();
}
}
The thumbnails of CMS images (Fegg\Controller\Up_dir::image()) are generated with this class.
Methods
Trim::setImage
Set target image and output file path
Trim::resize
Resize the image to fit in the specified size with keeping ratio
Trim::resizeFill
Resize the image with keeping ratio and filling the empty area (Like object-fit: contain)
Trim::resizeForce
Resize the image to the specified size ignoring ratio
Trim::resizeTrim
Resize the image with keeping ratio and trimming the overflow (Like object-fit: cover)
Trim::create
Save the image to the output path
Trim::view
Output the saved image to the browser