Package with functions created to facilitate the upload and manipulation of images to the server.
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.
- Requirements
- Installation
- Lib instance
- Set file
- Get file
- Simple complete example
- Image resize
- Image crop
- Image flip
- Image gamma correct
- Image rotate
- Image text
- Image watermarks
- Image filter negative
- Image filter gray scale
- Image filter edgedetect
- Image filter emboss
- Image filter gaussian blur
- Image filter selective blur
- Image filter mean removal
- Image filter smooth
- Image filter brightness
- Image filter contrast
- Image filter pixelate
- Image filter colorize
- Contributing
- Security
- Credits
- License
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.
It's recommended that you use Composer to install Slim.
$ composer require fernandozueet/php-upload-server
$upload = new FzUpload\Core();
//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
$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
]
]
//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
}
//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
}
//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
}
//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
}
//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
}
//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
}
//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
}
//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
}
//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
}
//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
}
//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
}
//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
}
//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
}
//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
}
//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
}
//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
}
//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
}
//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
}
//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
}
//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
}
Please see CONTRIBUTING for details.
If you discover security related issues, please email fernandozueet@hotmail.com instead of using the issue tracker.
The PHP Upload and Image Manipulation is licensed under the MIT license. See License File for more information.