2017 © Pedro Peláez
 

library image_compress

Compress image with callback support

image

codeawn/image_compress

Compress image with callback support

  • Tuesday, August 22, 2017
  • by codeawn
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2,109 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

composer require codeawn/image_compress

Compress from file upload form

``` php \Codeawn\image::uploadCompress($input, $args, $quality, $unlink);, (*1)


- **$input** : (string) input file name attribute, use [] for multiple file e.g `attribute[]` - **$args** : destination folder include `/` e.g `upload/` or `callback function` - **$quality** : (int) quality of compressed images - **$unlink** : (booelan) remove file source # Compress from string or array ``` php \Codeawn\image::imageCompress($input, $args, $quality, $unlink);
  • $input : file name include path or array e.g ["folder/file1.jpg","folder/file2.jpg"]to process multiple file

Example

HTML, (*2)

``` html , (*3)

 **PHP** 

``` php
if(isset($_POST['upload'])) {

    try{ if(\Codeawn\image::uploadCompress(
        "gambar", function ($file,$name) {
            // backup original files
            copy($file, "backup/".$name);
            // show current progress
            echo"processing : ".$name."<br>";
            // build new name based date & time
            $date = date("Ymd_his");
            $fname = $date."_".$name;
            // replace space with underscore
            $fname = str_replace(" ","_",$fname);
            // since compressed using imagejpeg function so rename non .jpg extension to .jpg
            $fname = preg_replace('/\.(png|jpeg|gif)$/', '.jpg', $fname);
            // return string filename with path
            return "uploaded/".$fname;
            // return false; for cancel process 
        }, 80, true
        )===false){
        throw new \Codeawn\FailException("upload failed","bad request!");
        } else{

        // this will show when no exception
        echo"Success <br>";
    }
    }
    catch(Codeawn\FailException $e) { echo $e->getTitle()," ",$e->getMessage();
    } 
} else{ echo"waiting upload .."; 
}

The Versions

22/08 2017

dev-master

9999999-dev https://github.com/codeawn

Compress image with callback support

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-gd *

 

The Development Requires

by Am K

upload image gd images compression compress

22/08 2017

3.0.0

3.0.0.0 https://github.com/codeawn

Compress image with callback support

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-gd *

 

The Development Requires

by Am K

upload image gd images compression compress

17/08 2017

2.0.0

2.0.0.0 https://github.com/codeawn

Compress image with callback support

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-gd *

 

The Development Requires

by Am K

upload image gd images compression compress

15/08 2017

1.0.0

1.0.0.0

Compress image with callback support

  Sources   Download

The Requires

  • php >=5.3.0
  • ext-gd *

 

by Am K