Download the PHP package sawastacks/kropify-laravel without Composer
On this page you can find all versions of the php package sawastacks/kropify-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sawastacks/kropify-laravel
More information about sawastacks/kropify-laravel
Files in sawastacks/kropify-laravel
Package kropify-laravel
Short Description Kropify is a tool that can be integrated into Laravel framework from version 8 and above for the purpose of giving users easy way to crop their profile pictures and cover images.
License MIT
Homepage https://github.com/sawastacks/kropify-laravel
Informations about the package kropify-laravel
!['Kropify'](img/kropify.png)
![GitHub release](https://img.shields.io/github/v/release/sawastacks/kropify-laravel) [![Total Downloads](https://poser.pugx.org/sawastacks/kropify-laravel/downloads)](https://packagist.org/packages/sawastacks/kropify-laravel) [![Package License](https://img.shields.io/badge/License-MIT-brightgreen.svg)](LICENSE)
Kropify
Sawa Stacks brought you easy cropping image tool for user profile picture, cover image, etc... that can be integrated into Laravel project.
NOTE:
Kropify
cannot be integrated into Laravel framework only. It has another php version that can be integrated into CodeIgniter and Core PHP projects.
What is a Kropify?
A Kropify is a tool that can be integrated into Laravel framework
, CodeIgniter framework
and Core PHP
projects for the purpose of giving users easy way to crop their profile pictures and covers. It uses JQuery 3.x library in it's functionality as dependency. That's why it is important to include JQuery library on current blade file.
Requirements
- PHP >= 7.2
- Composer is required
- Laravel 8.x, 9.x , 10.x and 11.x
- JQuery 3.x
- ⚠️This Version is only compatible with Image Intervenion v2
Installation
This package can be installed through composer require
. Before install this, make sure that your are working with PHP >= 7.2 in your system.
Just run the following command in your cmd or terminal:
-
Install the package via Composer:
The package will automatically register its service provider if your Laravel framework is 8.x or above. And also, If Image Intervention package was not installed before, This package will install Image Intervention package to your Laravel project.
-
Optionally, After you have installed Kropify, open your Laravel config file
config/app.php
and add the following lines.In the
$providers
array, add the service providers for this package. - After Kropify package installed, you need to publish its css and js minified files in Laravel public folder by running the following command in terminal:
Updating Package
When new Kropify version released and try to update the current package to the latest version, you will need to use composer update
command:
When package not updated by using the above command, use below command that will remove current package version and install new version of package.
After Kropify package updated, you need also to update its assets (css and js minified files) by running the following command in terminal:
For Kropify
directives, you have to run this command to get immediately changes in views.
Finally, It is neccessary to run the following command to autoload package files.
#
Usage
This package uses css and js minified files, that is why you first need to include this package assets on your blade file. Place the following directive inside <head>
tag of your blade file to including Kropify css file on page.
NOTICE:
Don't forgot to add CSRF
meta tags to every blade file included Kropify assets as shown in above example.
For Kropify Js file, you need to add the following directive or helper inside <body>
tag but before closing </body>
tag after including JQuery as shown in below example.
Package initialization
Suppose that you have an input file on your form for user profile picture:
Routes
When you want to initiate Kropify on that particular input file, you will use the following scripts.
Options
Option | Default | Description |
---|---|---|
viewMode |
1 | You can set this value to (1,2 or 3). But you can not add this option if you are happy with the default value which is 1. |
aspectRatio |
1 | You can add your custom cropped image ratio. You can use fractional numbers and float numbers. eg: 16/4 , 10/32 , 0.25 , 2.25 , etc... |
preview |
required | This option is very required. This is where you define the output element to preview the cropped image. Here, you must use jquery selector to select id="..." or class="..." of the img tag element where you want to display cropped image result. |
cancelButtonText |
Cancel | You can change this button text with your need and according to your language. |
resetButtonText |
Reset | You can change this button text with your need and according to your language. |
cropButtonText |
Crop | You can change this button text with your need and according to your language. |
maxSize |
2097152 | By default, this value set to the maximum size of 2MB .But, you can set your own maximum size of selected image. |
processURL |
- | This option is very required. You must define your url of croping selected image. eg: processURL : "{{ route('crop') }}" or processURL : "{{ url('crop') }}" |
showLoader |
true | If you want to display loading element when user croping the selected image, you can set this option to true. But if you do not want that loading element appears on page, set this option to false. |
animationClass |
pulse | If you want to animate cropping area, you may use this option by choosing one of three animation classes allowed pulse ,headShake ,fadeIn and pulse . By default, this value set to pulse class. |
fileName |
- | This will be used when want to specify or overwrite file name of the input file. |
Errors callback
This callback has two arguments, error
and text
Parameter | Description |
---|---|
error |
This prameter will return two types of errors invalidFileType and bigFileSize. You can make a if condition according to the returned error type. |
text |
You can alert this value eg : alert(message);. If you are using Toastr.js plugin, You may use toastr.error(text)' function to display error alert. |
In controller
To include Kropify class in controller is very simple. Just import the following lines on your controller.
To upload the cropped image you will use the following lines inside method:
The above lines will upload the cropped image in the specified path. The cropped image can be uploaded in Laravel public folder or in Laravel storage folder.
Very important function on the chain is maxWoH()
. This function will limit maximum dimensions (Width or Height) in px value of the uploaded image. If you do not need to compress and resize the cropped image, just do not add maxWoH()
to the Kropify upload function chain. Make sure that extension=gd
extension is enable in your server.
Get Cropped/Uploaded image details
When cropped image uploaded successfully, you can get the uploaded image information like name, size, width and Height. You can use these details when you need to store them into database. Below are examples of getting uploaded image details:
Not supported
1.
Currently, uploading cropped image using Laravel Livewire
is not supported. This package still in development, Once uploading cropped image in Laravel Livewire available, we will notify you.
You can not also upload image to AWS Amazon S3
.
2.
This package is still in development, that is why you can not make two or more instances on single page of this jquery scripts part.
Copyright and License
This package was written by Sawa Stacks and is released under the MIT License.
Copyright (c) 2023 - Sawa Stacks