Skip to content

File Atributes

ordent edited this page Dec 22, 2016 · 4 revisions

File Atributes

By adding your attribute name into $files array in your respective model. The library will automatically try to process the data as a file.

Here's a couple operation that you can set for the files.

Images

$files = ["avatar"];

Add the following form input in order to do operation to the uploaded images.

File Name

"avatar" : "files.jpg" // results : avatar_name = generated md5 of the file.

To set the filename

"avatar_name" : "test.png" // results : avatar_name = test.png

Library is clever enough to check if the name inputted have any extension or not, if there's no extension on the attribute name, it will grab the extension from the file and automatically append to the name

"avatar_name" : "test" // results : avatar_name = test.png

It also checking if the extension in the name is a proper extension for the file, giving a confidence that the file wont be saved with wrong extension

"avatar_name" : "test.pdf" // results : avatar_name = test.png

Image Size

You can also set the size of the image, if you are only set one of the size properties, the library will calculated based on image ratio with the new size.

"avatar_height" : "100"
"avatar_width" : "100"

There are a couple of operation when resizing the images, each have diferrent way to resize the image.

"avatar_operation" : "resize"

The image will be resized normally respecting the height and width that has been inputted. You can have a proper image ration by only inputting either width or height of the image, (not both).

"avatar_operation" : "crop"

The image will be cropped based on height and the image, it will originated at center and the excess of width and height will be abandoned.

"avatar_operation" : "fit"

This is the combination of the two techniques above. The image will be resized to the nearest image ratio of the original image, and then will crop based on the inputted image size.

Type

You can change the image type to different image type (jpg -> png) (png -> jpg). Careful though, wrong image type will resulted in corrupted saved file.

"avatar_type" : "png"

Quality

The quality of the saved image (0-100), less value means less quality of the image.

"avatar_quality" : 100
Clone this wiki locally