PHP Classes

File: test/upload.php

Recommend this page to a friend!
  Classes of Ujah Chigozie peter   Nano PHP Image Resize   test/upload.php   Download  
File: test/upload.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Nano PHP Image Resize
Resize local or remote images
Author: By
Last change: Update upload.php
Date: 4 months ago
Size: 1,035 bytes
 

Contents

Class file image Download
<?php
 
require_once __DIR__ "/autoload.php";
  use
Peterujah\NanoBlock\NanoImage;
  use
Peterujah\NanoBlock\UnsupportedImageException;
  if(isset(
$_FILES['image'])){
   
$ImageTemp = $_FILES['image']['tmp_name'];
   
$fileName = 'old-image.jpg';
   
$filePathAsset = __DIR__ . '/assets/img/nano/';
   
    if(!
is_dir($filePathAsset)){
     
mkdir($urlPathAsset, 0755, true);
    }

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

    if (@
move_uploaded_file($ImageTemp, $filePathAsset . $fileName)) {
     
$imagine = new NanoImage();
      try{
       
$image = $imagine->open($logoPath . $fileName);
 
       
$image->resize(360, 200, false);
       
$image->save($filePathAsset . $imageName, NanoImage::THUMBNAIL, 80);
 
       
$image->resize(116, 80, false);
       
$image->saveAs($filePathAsset . $imageName, NanoImage::THUMBNAIL, 100, $imagine::JPEG);
 
       
$image->free();
      }catch(
UnsupportedImageException $e){
        echo
$e->getMessage();
      }
    }
  }