kisphp/thumbnails

Kisphp thumbnails generator. Supports jpg, png, gif, webp images

1.6.1 2024-04-28 00:36 UTC

This package is auto-updated.

Last update: 2024-04-27 22:38:27 UTC


README

pipeline status coverage report

Latest Stable Version Total Downloads License Monthly Downloads

This class will help you to easily resize images and save them to disc or show them to user

Supported format:

  • jpg
  • jpg2000
  • png
  • gif
  • webp

Installation

composer require kisphp/thumbnails

Then add make sure you load composer autoloader:

require_once 'path/to/vendor/autoload.php';

Usage

<?php

require_once 'path/to/vendor/autoload.php';

$image = new \Kisphp\ImageResizer();

// load original image file
$image->load('/path/to/image/file.jpg');

// set where thumbnail will be saved (optional)
$image->setTarget('/path/to/thumbnail/file.jpg');

// resize image to a 300px width and dynamic height by aspect ratio 
$image->resize(300, 0);

// or
// resize image to a 300px height and dynamic width by aspect ratio 
$image->resize(0, 300);

// show image and save
$image->display(true);

Change thumbnail background color

If you crop the images, you can use a custom background color to integrate the thumbnail into your design

// set default background color (here will be red, default is white)
$image->setBackgroundColor(255, 0, 0);

Resize method usage

$image->resize(new_width, new_height, crop_image=true|false);

Show image without saving it

$image->display();

Note that these methods outputs header('Content-Type: image/..mime-type..')