Skip to content

PHP Upload and manipulation image, crop, resize, watermarks, filters, flip, rotate, image text and gamma correct

License

Notifications You must be signed in to change notification settings

FernandoZueet/php-upload-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Upload and Image Manipulation

Package with functions created to facilitate the upload and manipulation of images to the server.

Safety Notices

To ensure the security of uploads on the server it is highly recommended that the files be uploaded outside the site's public folder.

This library does not validate the submission of any files. Use a validation library of your choice.


Documentation


Requirements

This will install PHP Upload and Image Manipulation and all required dependencies. PHP Upload and Image Manipulation requires PHP 7.0.0 or newer. To create derived images GD should be installed on your server.

Installation

It's recommended that you use Composer to install Slim.

$ composer require fernandozueet/php-upload-server

Lib instance

$upload = new FzUpload\Core();

Set file

//url file
$upload->setFile([
    'http://especiais.g1.globo.com/educacao/guia-de-carreiras/2017/teste-vocacional/assets/teste_vocacional_logo.png',
    'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png'
]);
//php file
$upload->setFile($_FILES['file_x']);
//slim framework file
$upload->setFile($request->getUploadedFiles());
//symphony or laravel framework file
$upload->setFile($request->file_x);

Get file

//get file
$return = $upload->getFile();
//value returned
array:2 [
  0 => array:9 [
    "temp" => "C:\xampp\tmp\php2FA2.tmp"
    "extension" => "jpg"
    "image" => array:2 [
      "width" => 500
      "height" => 500
    ]
    "mimeType" => "image/jpeg"
    "name" => "45373949_1GG"
    "completeName" => "45373949_1GG.jpg"
    "randomName" => "c42264551c22b94992a128b39ae84986"
    "completeRandomName" => "c42264551c22b94992a128b39ae84986.jpg"
    "size" => 32643
  ]
  1 => array:9 [
    "temp" => "C:\xampp\tmp\php2FA3.tmp"
    "extension" => "jpg"
    "image" => array:2 [
      "width" => 1200
      "height" => 1200
    ]
    "mimeType" => "image/jpeg"
    "name" => "guarda-roupa-casal-com-espelho-3-portas-de-correr-lara-ciwt-D_NQ_NP_685005-MLB25713052454_062017-F"
    "completeName" => "guarda-roupa-casal-com-espelho-3-portas-de-correr-lara-ciwt-D_NQ_NP_685005-MLB25713052454_062017-F.jpg"
    "randomName" => "c099d9ec06382af2ba3985aa67b4025e"
    "completeRandomName" => "c099d9ec06382af2ba3985aa67b4025e.jpg"
    "size" => 221866
  ]
]

Simple complete example

//lib instance
$upload = new FzUpload\Core();

//custom name (optional)
//$upload->setFileName('newName');

//original name files (optional)
//$upload->setOriginalName();

//set file
$upload->setFile(['https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png']);

//get file 
$files = $upload->getFile();

//save file in C:\teste\p and C:\teste\m
$upload->setSaveDirectory(["C:\\teste\p","C:\\teste\m"]);

//save image as. Possible values: (jpg|quality - 0 to 100, png|quality - 0 to 100, gif, webp|quality - 0 to 100)
$upload->setSaveImageAs(['jpg|100','png|100','gif','webp|100']);

//upload files
$upload->uploadFile();

//save file to local server
if($upload->saveLocal()) {

    //files uploaded
    $filesUploaded = $upload->getSavedFiles();

}else{
    //error
}

Image resize

//lib instance
$upload = new FzUpload\Core();

//set file
$upload->setFile(['https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png']);

//save file in C:\teste\p and C:\teste\m
$upload->setSaveDirectory(["C:\\teste\p","C:\\teste\m"]);

//save image as. Possible values: (jpg|quality - 0 to 100, png|quality - 0 to 100, gif, webp|quality - 0 to 100)
$upload->setSaveImageAs(['jpg|100','png|100','gif','webp|100']);

//image resize 
//int $width, int $height, bool $proportion = true
$upload->imageResize(100, 200);

//save file to local server
if($upload->saveLocal()) {
    //success
}else{
    //error
}

Image crop

//lib instance
$upload = new FzUpload\Core();

//set file
$upload->setFile(['https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png']);

//save file in C:\teste\p and C:\teste\m
$upload->setSaveDirectory(["C:\\teste\p","C:\\teste\m"]);

//save image as. Possible values: (jpg|quality - 0 to 100, png|quality - 0 to 100, gif, webp|quality - 0 to 100)
$upload->setSaveImageAs(['jpg|100','png|100','gif','webp|100']);

//image crop
//int $x, int $y, int $width, int $height
$upload->imageCrop(2, 2, 300, 200);

//save file to local server
if($upload->saveLocal()) {
    //success
}else{
    //error
}

Image flip

//lib instance
$upload = new FzUpload\Core();

//set file
$upload->setFile(['https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png']);

//save file in C:\teste\p and C:\teste\m
$upload->setSaveDirectory(["C:\\teste\p","C:\\teste\m"]);

//save image as. Possible values: (jpg|quality - 0 to 100, png|quality - 0 to 100, gif, webp|quality - 0 to 100)
$upload->setSaveImageAs(['jpg|100','png|100','gif','webp|100']);

//image flip
//int mode - Possible values: (IMG_FLIP_HORIZONTAL, IMG_FLIP_VERTICAL, IMG_FLIP_BOTH)
$upload->imageFlip(IMG_FLIP_VERTICAL);

//save file to local server
if($upload->saveLocal()) {
    //success
}else{
    //error
}

Image gamma correct

//lib instance
$upload = new FzUpload\Core();

//set file
$upload->setFile(['https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png']);

//save file in C:\teste\p and C:\teste\m
$upload->setSaveDirectory(["C:\\teste\p","C:\\teste\m"]);

//save image as. Possible values: (jpg|quality - 0 to 100, png|quality - 0 to 100, gif, webp|quality - 0 to 100)
$upload->setSaveImageAs(['jpg|100','png|100','gif','webp|100']);

//image gamma correct
//float $inputgamma, float $outputgamma
$upload->imageGammaCorrect(1.0, 1.537);

//save file to local server
if($upload->saveLocal()) {
    //success
}else{
    //error
}

Image rotate

//lib instance
$upload = new FzUpload\Core();

//set file
$upload->setFile(['https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png']);

//save file in C:\teste\p and C:\teste\m
$upload->setSaveDirectory(["C:\\teste\p","C:\\teste\m"]);

//save image as. Possible values: (jpg|quality - 0 to 100, png|quality - 0 to 100, gif, webp|quality - 0 to 100)
$upload->setSaveImageAs(['jpg|100','png|100','gif','webp|100']);

//image rotate
//int $rotate - Possible values: (0 to 360)
$upload->imageRotate(80);

//save file to local server
if($upload->saveLocal()) {
    //success
}else{
    //error
}

Image text

//lib instance
$upload = new FzUpload\Core();

//set file
$upload->setFile(['https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png']);

//save file in C:\teste\p and C:\teste\m
$upload->setSaveDirectory(["C:\\teste\p","C:\\teste\m"]);

//save image as. Possible values: (jpg|quality - 0 to 100, png|quality - 0 to 100, gif, webp|quality - 0 to 100)
$upload->setSaveImageAs(['jpg|100','png|100','gif','webp|100']);

//image text
//string $text, string $fontFile, int $size, array $rgbColor, int $angle - (0 to 90), int $x, int $y
$upload->imageText('Test test', 'C:\Windows\Fonts\arial.ttf', 16, [255,0,0], 0, 30, 30);

//save file to local server
if($upload->saveLocal()) {
    //success
}else{
    //error
}

Image watermarks

//lib instance
$upload = new FzUpload\Core();

//set file
$upload->setFile(['https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png']);

//save file in C:\teste\p and C:\teste\m
$upload->setSaveDirectory(["C:\\teste\p","C:\\teste\m"]);

//save image as. Possible values: (jpg|quality - 0 to 100, png|quality - 0 to 100, gif, webp|quality - 0 to 100)
$upload->setSaveImageAs(['jpg|100','png|100','gif','webp|100']);

//image watermarks
//int $bottom, int $right, string $imageLogo
$upload->imageWatermarks(10, 10, 'C:\teste\logo.png');

//save file to local server
if($upload->saveLocal()) {
    //success
}else{
    //error
}

Image filter negative

//lib instance
$upload = new FzUpload\Core();

//set file
$upload->setFile(['https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png']);

//save file in C:\teste\p and C:\teste\m
$upload->setSaveDirectory(["C:\\teste\p","C:\\teste\m"]);

//save image as. Possible values: (jpg|quality - 0 to 100, png|quality - 0 to 100, gif, webp|quality - 0 to 100)
$upload->setSaveImageAs(['jpg|100','png|100','gif','webp|100']);

//image filter
$upload->imageFilter(IMG_FILTER_NEGATE);

//save file to local server
if($upload->saveLocal()) {
    //success
}else{
    //error
}

Image filter gray scale

//lib instance
$upload = new FzUpload\Core();

//set file
$upload->setFile(['https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png']);

//save file in C:\teste\p and C:\teste\m
$upload->setSaveDirectory(["C:\\teste\p","C:\\teste\m"]);

//save image as. Possible values: (jpg|quality - 0 to 100, png|quality - 0 to 100, gif, webp|quality - 0 to 100)
$upload->setSaveImageAs(['jpg|100','png|100','gif','webp|100']);

//image filter
$upload->imageFilter(IMG_FILTER_GRAYSCALE);

//save file to local server
if($upload->saveLocal()) {
    //success
}else{
    //error
}

Image filter edgedetect

//lib instance
$upload = new FzUpload\Core();

//set file
$upload->setFile(['https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png']);

//save file in C:\teste\p and C:\teste\m
$upload->setSaveDirectory(["C:\\teste\p","C:\\teste\m"]);

//save image as. Possible values: (jpg|quality - 0 to 100, png|quality - 0 to 100, gif, webp|quality - 0 to 100)
$upload->setSaveImageAs(['jpg|100','png|100','gif','webp|100']);

//image filter
$upload->imageFilter(IMG_FILTER_EDGEDETECT);

//save file to local server
if($upload->saveLocal()) {
    //success
}else{
    //error
}

Image filter emboss

//lib instance
$upload = new FzUpload\Core();

//set file
$upload->setFile(['https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png']);

//save file in C:\teste\p and C:\teste\m
$upload->setSaveDirectory(["C:\\teste\p","C:\\teste\m"]);

//save image as. Possible values: (jpg|quality - 0 to 100, png|quality - 0 to 100, gif, webp|quality - 0 to 100)
$upload->setSaveImageAs(['jpg|100','png|100','gif','webp|100']);

//image filter
$upload->imageFilter(IMG_FILTER_EMBOSS);

//save file to local server
if($upload->saveLocal()) {
    //success
}else{
    //error
}

Image filter gaussian blur

//lib instance
$upload = new FzUpload\Core();

//set file
$upload->setFile(['https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png']);

//save file in C:\teste\p and C:\teste\m
$upload->setSaveDirectory(["C:\\teste\p","C:\\teste\m"]);

//save image as. Possible values: (jpg|quality - 0 to 100, png|quality - 0 to 100, gif, webp|quality - 0 to 100)
$upload->setSaveImageAs(['jpg|100','png|100','gif','webp|100']);

//image filter
$upload->imageFilter(IMG_FILTER_GAUSSIAN_BLUR);

//save file to local server
if($upload->saveLocal()) {
    //success
}else{
    //error
}

Image filter selective blur

//lib instance
$upload = new FzUpload\Core();

//set file
$upload->setFile(['https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png']);

//save file in C:\teste\p and C:\teste\m
$upload->setSaveDirectory(["C:\\teste\p","C:\\teste\m"]);

//save image as. Possible values: (jpg|quality - 0 to 100, png|quality - 0 to 100, gif, webp|quality - 0 to 100)
$upload->setSaveImageAs(['jpg|100','png|100','gif','webp|100']);

//image filter
$upload->imageFilter(IMG_FILTER_SELECTIVE_BLUR);

//save file to local server
if($upload->saveLocal()) {
    //success
}else{
    //error
}

Image filter mean removal

//lib instance
$upload = new FzUpload\Core();

//set file
$upload->setFile(['https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png']);

//save file in C:\teste\p and C:\teste\m
$upload->setSaveDirectory(["C:\\teste\p","C:\\teste\m"]);

//save image as. Possible values: (jpg|quality - 0 to 100, png|quality - 0 to 100, gif, webp|quality - 0 to 100)
$upload->setSaveImageAs(['jpg|100','png|100','gif','webp|100']);

//image filter
$upload->imageFilter(IMG_FILTER_MEAN_REMOVAL);

//save file to local server
if($upload->saveLocal()) {
    //success
}else{
    //error
}

Image filter smooth

//lib instance
$upload = new FzUpload\Core();

//set file
$upload->setFile(['https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png']);

//save file in C:\teste\p and C:\teste\m
$upload->setSaveDirectory(["C:\\teste\p","C:\\teste\m"]);

//save image as. Possible values: (jpg|quality - 0 to 100, png|quality - 0 to 100, gif, webp|quality - 0 to 100)
$upload->setSaveImageAs(['jpg|100','png|100','gif','webp|100']);

//image filter
$upload->imageFilter(IMG_FILTER_SMOOTH);

//save file to local server
if($upload->saveLocal()) {
    //success
}else{
    //error
}

Image filter brightness

//lib instance
$upload = new FzUpload\Core();

//set file
$upload->setFile(['https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png']);

//save file in C:\teste\p and C:\teste\m
$upload->setSaveDirectory(["C:\\teste\p","C:\\teste\m"]);

//save image as. Possible values: (jpg|quality - 0 to 100, png|quality - 0 to 100, gif, webp|quality - 0 to 100)
$upload->setSaveImageAs(['jpg|100','png|100','gif','webp|100']);

//image filter - (-255 to 255)
$upload->imageFilter(IMG_FILTER_BRIGHTNESS, 100);

//save file to local server
if($upload->saveLocal()) {
    //success
}else{
    //error
}

Image filter contrast

//lib instance
$upload = new FzUpload\Core();

//set file
$upload->setFile(['https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png']);

//save file in C:\teste\p and C:\teste\m
$upload->setSaveDirectory(["C:\\teste\p","C:\\teste\m"]);

//save image as. Possible values: (jpg|quality - 0 to 100, png|quality - 0 to 100, gif, webp|quality - 0 to 100)
$upload->setSaveImageAs(['jpg|100','png|100','gif','webp|100']);

//image filter - (-100 to 100)
$upload->imageFilter(IMG_FILTER_CONTRAST, -50);

//save file to local server
if($upload->saveLocal()) {
    //success
}else{
    //error
}

Image filter pixelate

//lib instance
$upload = new FzUpload\Core();

//set file
$upload->setFile(['https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png']);

//save file in C:\teste\p and C:\teste\m
$upload->setSaveDirectory(["C:\\teste\p","C:\\teste\m"]);

//save image as. Possible values: (jpg|quality - 0 to 100, png|quality - 0 to 100, gif, webp|quality - 0 to 100)
$upload->setSaveImageAs(['jpg|100','png|100','gif','webp|100']);

//image filter 
$upload->imageFilter(IMG_FILTER_PIXELATE, 3);

//save file to local server
if($upload->saveLocal()) {
    //success
}else{
    //error
}

Image filter colorize

//lib instance
$upload = new FzUpload\Core();

//set file
$upload->setFile(['https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png']);

//save file in C:\teste\p and C:\teste\m
$upload->setSaveDirectory(["C:\\teste\p","C:\\teste\m"]);

//save image as. Possible values: (jpg|quality - 0 to 100, png|quality - 0 to 100, gif, webp|quality - 0 to 100)
$upload->setSaveImageAs(['jpg|100','png|100','gif','webp|100']);

//image filter 
//arg1 (0 to 255), arg2 (0 to 255), arg3 (0 to 255), arg4 (0 to 127)
$upload->imageFilter(IMG_FILTER_COLORIZE, 64, 193, 198, 50);

//save file to local server
if($upload->saveLocal()) {
    //success
}else{
    //error
}

Contributing

Please see CONTRIBUTING for details.

Security

If you discover security related issues, please email fernandozueet@hotmail.com instead of using the issue tracker.

Credits

License

The PHP Upload and Image Manipulation is licensed under the MIT license. See License File for more information.