Set aspect ratio and crop size
Demo of Illustrated
Note: as this is a demo, you can't really upload files. However, you can browse for images on your system and test the Uploader widget.
In this case, the aspect ratio (width/height) is set to 1.778 (16/9), and the crop size to 600.
In the database, only the field with the file name of the cropped image is stored.
Data in the database
Click on the thumbnail to see examples of img file(s) on the server.
Configuration of the model
<?php class <model> extends \yii\db\ActiveRecord { ... public function behaviors() { return [ [ 'class' => 'sjaakp\illustrated\Illustrated', 'attributes' => [ 'img' => [ 'aspectRatio' => 1.778, 'cropSize' => 600 ] ] ], ... // other behaviors ]; } ... }
Settings for the Uploader widget
<?php use sjaakp\illustrated\Uploader; ?> <?php $form = ActiveForm::begin([ 'options' => ['enctype' => 'multipart/form-data'] // important, needed for file upload ]); ?> ... // other form fields <?= $form->field($model, 'img')->widget(Uploader::class, [ 'deleteOptions' => false // suppress rendering of delete checkbox ]) ?> ... <?php ActiveForm::end(); ?>