Download the PHP package sjaakp/yii2-illustrated-behavior without Composer

On this page you can find all versions of the php package sjaakp/yii2-illustrated-behavior. 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 yii2-illustrated-behavior

Illustrated 2.0

Behavior for Yii2 ActiveRecord

With associated Cropper-widget

Latest Stable Version Total Downloads License

Illustrated 2.0 is a Behavior for the Yii2 framework that makes any ActiveRecord, well, illustrated. It links the ActiveRecord to one or more image files. The images have strict proportions, allowing for a clean layout of views and other pages. The images may be saved in several resolutions.

The Illustrated 2.0 behavior co-operates with the enclosed CropperWidget widget. This lets the user crop the image, before uploading it to the server.

Here is a demo of the Illustrated 2.0 behavior and its associated CropperWidget.

Note that the current version (2.0.0) is changed considerably from previous versions. It should be far easier to use. Please consult this document carefully.


Installation

Install Illustrated 2.0 with Composer. Either add the following to the require section of your composer.json file:

"sjaakp/yii2-illustrated-behavior": "*"

Or run:

composer require sjaakp/yii2-illustrated-behavior "*"

You can manually install Illustrated 2.0 by downloading the source in ZIP-format.

Note that Illustrated 2.0 needs PHP version 8.1 or later.


Usage of Illustrated

Illustrated 2.0 is used like any Behavior of an ActiveRecord. The code should look something like this:

    ...     // other form fields

    <?= $form->field($model, 'picture')->widget(CropperWidget::class, [
           ...      // CropperWidget options
        ]) ?>
    ...
    <?= Html::submitButton('Submit') ?>

CropperWidget displays a control for file upload combined with controls to crop and rotate the image. It is based on my Cropper 2.0 JavaScript widget.

Note that the ActiveForm must have the option 'enctype' set to 'multipart/form-data'.

By far the most important option of CropperWidget is aspect. This sets the aspect ratio of the cropped immage.

It can be set to one one of the following strings:

Alternatively, you can set aspect to a float between 0.2 and 5.0.

CropperWidget has some other options too. Please refer tot the documentation for Cropper 2.0

Example

To set the aspect ratio to 'portrait' (0.75) one would use:

use sjaakp\illustrated\CropperWidget;

    ...   
    <?= $form->field($model, 'picture')->widget(CropperWidget::class, [
        'aspect' => 'portrait'
        ]) ?>

    ...

Illustrated 2.0 functions

These functions become methods of the ActiveRecord that owns the Illustrated 2.0 Behavior.

getImgHtml()

function getImgHtml( $attribute, $options = [] )

Gets a complete HTML <img> element of the uploaded and cropped illustration. If cropWidth is set and cropSteps is greater than zero, a srcset is included.

Note that for srcset to be effective, you have to set the sizes value in $options. For details, see here.

The easiest way to display the illustration stored in the attribute 'picture' in a view is:

... 
<?= $model->getImgHtml('picture') ?>
...

getSrc()

function getSrc( $attribute, $step = 0 )

Gets the source URL of (one of the variants of) the uploaded and cropped illustration. Returns null if not available.

getSrcSet()

function getSrcSet( $attribute )

Gets the srcset of the uploaded and cropped illustration. Returns "" if cropWidth is not set.

deleteFiles()

function deleteFiles( $attribute )

Deletes the image file(s) and clears attribute.


Illustrated 2.0 options

attributes

array List of illustration properties key => value.

Array member key is the name of the attribute that stores the file name of the resulting cropped image.

value is an array with the following properties (all are optional):

mime

MIME type of saved, cropped image(s). If null, cropped images will be saved with the same MIME type as the original. Default: 'image/avif'. AVIF is a recent (2019) image file format which is in many ways superior to JPEG. It is supported by all modern browsers.

directory

Directory (or alias) where cropped images are saved.

If null (default), the directory will be '@webroot/<$illustrationDirectory>/<table name>', where <table name> is the table name of the ActiveRecord.

baseUrl

URL (or alias) where cropped images reside.

If null (default), the URL will be '@web/<$illustrationDirectory>/<table name>', where <table name> is the table name of the ActiveRecord.

illustrationDirectory

Name of subdirectory under '@webroot' where cropped images are stored. Default: 'illustrations'. If directory is anything else than null, illustrationDirectory is ignored

noImage

HTML returned if no image is available, i.e. $imgAttribute is empty. Default: '' (empty text).

fileValidation

Array with extra parameters for the validation of the file attribute. By default, only the file types and the number of files are tested.

You may add things like maximum file size here. See FileValidator. Default: [] (empty array).

tooSmallError

Error message template for images that are too small to crop. Parameters: original file name, width, and height. Default: 'Image "%s" is too small (%d×%d).'.

uploadError

Error message template for upload errors. Parameter: error number. See here. Default: 'Upload Error %d.'.


CropperWidget options

options

Client options such as aspect for the Cropper 2.0 control. See Cropper documentation.

translations

Optional translations for the Cropper 2.0 control. See Cropper documentation.

FAQ

Why am I getting an error like 'Trying to get property of non-object'?

Why can't I change the cropping of an illustration if I try to update an illustrated document?


All versions of yii2-illustrated-behavior with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
yiisoft/yii2 Version ~2.0.49
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 sjaakp/yii2-illustrated-behavior contains the following files

Loading the files please wait ....