Download the PHP package qcod/laravel-imageup without Composer

On this page you can find all versions of the php package qcod/laravel-imageup. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-imageup

Laravel ImageUp

Latest Version on Packagist Build Status Total Downloads

The qcod/laravel-imageup is a trait which gives you auto upload, resize and crop for image feature with tons of customization.

Installation

You can install the package via composer:

The package will automatically register itself. In case you need to manually register it you can by adding it in config/app.php providers array:

You can optionally publish the config file with:

It will create config/imageup.php with all the settings.

Getting Started

To use this trait you just need to add use HasImageUploads on the Eloquent model and define all the fields which needs to store the images in database.

Model

Once you marked all the image fields in model it will auto upload the image whenever you save the model by hooking in Model::saved() event. It will also update the database with new stored file path and if finds old image it will be deleted once new image is uploaded.

Image field should be as as VARCHAR in database table to store the path of uploaded image.

In Controller

Make sure to run php artisan storage:link to see the images from public storage disk

That's it, with above setup when ever you hit store method with post request and if cover or avatar named file is present on request() it will be auto uploaded.

Upload Field options

ImageUp gives you tons of customization on how the upload and resize will be handled from defined field options, following are the things you can customize:

Customize filename

In some case you will need to customize the saved filename. By default it will be $file->hashName() generated hash.

You can do it by adding a method on the model with {fieldName}UploadFilePath naming convention:

Above will always save uploaded cover image as uploads/1-cover-image.jpg.

Make sure to return only relative path from override method.

Request file will be passed as $file param in this method, so you can get the extension or original file name etc to build the filename.

Available methods

You are not limited to use auto upload image feature only. This trait will give you following methods which you can use to manually upload and resize image.

Note: Make sure you have disabled auto upload by setting protected $autoUploadImages = false; on model or dynamiclly by calling $model->disableAutoUpload(). You can also disable it for specifig field by calling $model->setImagesField(['cover' => ['auto_upload' => false]); otherwise you will be not seeing your manual uploads, since it will be overwritten by auto upload upon model save.

$model->uploadImage($imageFile, $field = null) / $model->uploadFile($docFile, $field = null)

Upload image/file for given $field, if $field is null it will upload to first image/file option defined in array.

$model->setImagesField($fieldsOptions) / $model->setFilesField($fieldsOptions)

You can also set the image/file fields dynamically by calling $model->setImagesField($fieldsOptions) / $model->setFilesField($fieldsOptions) with field options, it will replace fields defined on model property.

$model->hasImageField($field) / $model->hasFileField($field)

To check if field is defined as image/file field.

$model->deleteImage($filePath) / $model->deleteFile($filePath)

Delete any image/file if it exists.

$model->resizeImage($imageFile, $fieldOptions)

If you have image already you can call this method to resize it with the same options we have used for image fields.

$model->cropTo($x, $y)->resizeImage($imageFile, $field = null)

You can use this cropTo() method to set the x and y coordinates of cropping. It will be very useful if you are getting coordinate from some sort of font-end image cropping library.

$model->imageUrl($field) / $model->fileUrl($field)

Gives uploaded file url for given image/file field.

$model->imageTag($field, $attribute = '')

It gives you <img /> tag for a field.

Hooks

Hooks allow you to apply different type of customizations or any other logic that you want to take place before or after the image is saved.

Definition types

You can define hooks by specifying a class name

The hook class must have a method named handle that will be called when the hook is triggered. An instance of the intervention image will be passed to the handle method.

The class based hooks are resolved through laravel ioc container, which allows you to inject any dependencies through the constructor.

Keep in mind you will be getting resized image in before and after save hook handler if you have defined field option with width or height. Sure you can get original image from request()->file('avatar') any time you want.

The second type off hook definition is callback hooks.

The callback will receive the intervention image instance argument as well.

Hook types

There are two types of hooks a before_save and after_save hooks.

The before_save hook is called just before the image is saved to the disk. Any changes made to the intervention image instance within the hook will be applied to the output image.

The after_save hook is called right after the image was saved to the disk.

Config file

Changelog

Please see CHANGELOG for more information on what has changed recently.

Testing

The package contains some integration/smoke tests, set up with Orchestra. The tests can be run via phpunit.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

About QCode.in

QCode.in (https://www.qcode.in) is blog by Saqueib which covers All about Full Stack Web Development.

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-imageup with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3|^8.0
laravel/framework Version ~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
intervention/image Version ^2.4|^3.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package qcod/laravel-imageup contains the following files

Loading the files please wait ....