Illustrated is an extension for the Yii framework 2.0. It is a Behavior that makes any ActiveRecord, well, illustrated. It links the ActiveRecord to one (or possibly more) image files. The images have strict proportions, allowing for a clean layout of views and other pages. The uploaded images may have several resolutions.
The Illustrated behavior co-operates with the enclosed CropperWidget widget. This lets the user crop the image, before uploading it to the server.
The relevant code in the ActiveRecord
<?php use sjaakp\illustrated\Illustrated; class Demo extends \yii\db\ActiveRecord { //... public function behaviors() { return [ [ 'class' => Illustrated::class, 'attributes' => [ 'picture' => [ 'cropWidth' => 580, 'cropSteps' => 4, ] ] ] ]; } //... }
The code in the View
<?php $form = ActiveForm::begin([ 'options' => [ 'enctype' => 'multipart/form-data', ] ]); ?> <?= $form->field($model, 'picture')->widget(CropperWidget::class, [ 'options' => [ 'aspect' => 'portrait' ] ]) ?> ... <?php ActiveForm::end(); ?>