PHP Classes

Nano PHP Image Resize: Resize local or remote images

Recommend this page to a friend!
  Info   View files Example   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 117 This week: 1All time: 9,490 This week: 380Up
Version License PHP version Categories
nano-image 1.0.1GNU General Publi...5PHP 5, Graphics


This class can resize local or remote images.

It can take an image's path or URL and create a resized copy of the image in a given local directory.

The class can create resized images that preserve the ratio between the width and height of the original image.

Picture of Ujah Chigozie peter
  Performance   Level  
Name: Ujah Chigozie peter <contact>
Classes: 21 packages by
Country: Nigeria Nigeria
Age: 32
All time rank: 215110 in Nigeria Nigeria
Week rank: 78 Up3 in Nigeria Nigeria Up
Innovation award
Innovation award
Nominee: 9x


require_once __DIR__ "/autoload.php";

$ImageTemp = $_FILES['image']['tmp_name'];
$fileName = 'old-image.jpg';
$filePathAsset = __DIR__ . '/assets/img/nano/';
mkdir($urlPathAsset, 0777, true);
chmod($urlPathAsset, 0755);

file_exists($filePathAsset . $fileName)){
unlink($filePathAsset . $fileName);

    if (@
move_uploaded_file($ImageTemp, $filePathAsset . $fileName)) {
$imagine = new Peterujah\NanoBlock\NanoImage();
$image = $imagine->open($logoPath . $fileName);

$image->resize(360, 200, false);
$image->save($filePathAsset . $imageName, false, 80, $imagine::JPEG);

$image->resize(116, 80, false);
$image->save($filePathAsset . $imageName, true, 100, $imagine::JPEG);



Nano Image

NanoImage is a simple php image resize class. It can resize image and display it in browser or save image in a directory


Installation is super-easy via Composer:

composer require peterujah/nano-imag

Basic Usage

$img = Peterujah\NanoBlock\NanoImage();

Initalize nano image class for use

Open and load image from by passing the directory path & file name

$img->open(__DIR__ . "/path/to/assets/image.jpg");

Or load string containing the image data.


Resize image with exact width and height passed, example 200x200. To resize image using aspect ratio set the thrid parameter to true

$img->resize(200, 200, false||true);

Once image manipulation is done display the output image on browser. Pass qaulity of image


Save image to directory, first parameter specify the path, second default is null while quality is 90 by default

$img->save(__DIR__ . "/path/to/assets/new-image.jpg", NanoImage::THUMBNAIL || null, $quality);

Save image as

$img->saveAs($to, NanoImage::THUMBNAIL || null, $quality, self::JPEG)

Replace existing image with new one

$img->replace($to, $quality)

Remove temp image after editing and free momory


Free memory


  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Files folder imagetest (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file package.json Data Auxiliary data
Accessible without login Plain text file Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file NanoImage.php Class Class source

  Files folder image Files  /  test  
File Role Description
  Accessible without login Plain text file upload.php Example Example script

 Version Control Unique User Downloads Download Rankings  
This week:1
All time:9,490
This week:380Up