CrudAdmin automates uploading files and images into the administration. Working with them afterwards — resizing in particular — is handled by a small layer on top.

Uploading a file

Define a file field in the model.
The interface generates the upload field with the matching validation and handles the transfer to the server.
File upload field generated in the administration form

Reading a file from a model

$image holds the image represented by the Admin\Helpers\File class, which simplifies rendering the file in a template and working with it.
Dump of the File helper class instance
Rendered in a template, the class returns the full path to the file on the server.
The src attribute holds the full path to the file, for example https://example.com/uploads/.../my-uploaded-file.png.

Resizing images

The Admin\Helpers\File class can resize images directly in the template. resize($width, $height) takes the width as its first argument and the height as its second. With both defined, the image is cropped to the correct ratio. With only one defined, the other is calculated from the ratio.
The crop runs on the first request for the image and is stored on the server for later requests.

Advanced image operations

The File class uses Intervention Image, so it can perform any operation that library supports. The image($mutators) method takes an array whose keys are the function names and whose values are the arguments of those functions.
This example crops the image with fit and then blurs it with blur. See the Intervention Image documentation for fit and blur.

Helper methods

delete

Removes the file from the server.

download

Returns a link that forces the browser to download the file instead of displaying it.

filesize

Returns the exact file size in B/Kb/Mb/Gb depending on its size.
Pass false for the raw size.