public function actionImage($id) { $success = null; if ($photo = Photo::findOne($id)) { $oldImage = $photo->image; $photo->image = UploadedFile::getInstance($photo, 'image'); if ($photo->image && $photo->validate(['image'])) { $photo->image = Image::upload($photo->image, 'photos', Photo::PHOTO_MAX_WIDTH); if ($photo->image) { if ($photo->save()) { @unlink(Yii::getAlias('@webroot') . $oldImage); $success = ['message' => Yii::t('easyii', 'Photo uploaded'), 'photo' => ['image' => $photo->image, 'thumb' => Image::thumb($photo->image, Photo::PHOTO_THUMB_WIDTH, Photo::PHOTO_THUMB_HEIGHT)]]; } else { @unlink(Yii::getAlias('@webroot') . $photo->image); $this->error = Yii::t('easyii', 'Update error. {0}', $photo->formatErrors()); } } else { $this->error = Yii::t('easyii', 'File upload error. Check uploads folder for write permissions'); } } else { $this->error = Yii::t('easyii', 'File is incorrect'); } } else { $this->error = Yii::t('easyii', 'Not found'); } return $this->formatResponse($success); }
/** * Creates thumb from model->image attribute with specified width and height. * @param int|null $width * @param int|null $height * @param bool $crop if false image will be resize instead of cropping * @return string */ public function thumb($width = null, $height = null, $crop = true) { if ($this->image && ($width || $height)) { return Image::thumb($this->image, $width, $height, $crop); } return ''; }
use yii\widgets\ActiveForm; use yii\easyii\widgets\Redactor; use yii\easyii\widgets\SeoForm; $module = $this->context->module->id; $form = ActiveForm::begin(['enableAjaxValidation' => true, 'options' => ['enctype' => 'multipart/form-data', 'class' => 'model-form']]); echo $form->field($model, 'title'); ?> <?php if ($this->context->module->settings['articleThumb']) { ?> <?php if ($model->image) { ?> <img src="<?php echo Image::thumb($model->image, 240); ?> "> <a href="<?php echo Url::to(['/admin/' . $module . '/items/clear-image', 'id' => $model->primaryKey]); ?> " class="text-danger confirm-delete" title="<?php echo Yii::t('easyii', 'Clear image'); ?> "><?php echo Yii::t('easyii', 'Clear image'); ?> </a> <?php } ?>
use yii\easyii\modules\gallery\api\Gallery; use yii\easyii\modules\page\api\Page; use yii\helpers\Html; use yii\helpers\Url; $page = Page::get('page-gallery'); $this->title = $page->seo('title', $page->model->title); $this->params['breadcrumbs'][] = $page->model->title; ?> <h1><?php echo $page->seo('h1', $page->title); ?> </h1> <br/> <?php foreach (Gallery::cats() as $album) { ?> <a class="center-block" href="<?php echo Url::to(['gallery/view', 'slug' => $album->slug]); ?> "> <?php echo Html::img(Image::thumb($album->image, 160, 120)); ?> <br/><?php echo $album->title; ?> </a> <br/> <?php }
echo Yii::t('easyii', 'Image'); ?> </th> <th><?php echo Yii::t('easyii', 'Description'); ?> </th> <th width="150"></th> </tr> </thead> <tbody> <?php foreach ($photos as $photo) { ?> <?php echo str_replace(['{{photo_id}}', '{{photo_thumb}}', '{{photo_image}}', '{{photo_description}}'], [$photo->primaryKey, Image::thumb($photo->image, Photo::PHOTO_THUMB_WIDTH, Photo::PHOTO_THUMB_HEIGHT), $photo->image, $photo->description], $photoTemplate); ?> <?php } ?> </tbody> </table> <p class="empty" style="display: <?php echo count($photos) ? 'none' : 'block'; ?> ;"><?php echo Yii::t('easyii', 'No photos uploaded yet'); ?> .</p> <?php
public function getCrop($width, $height) { return \yii\easyii\helpers\Image::thumb($this->model->image, $width, $height); }
<?php use yii\easyii\helpers\Image; use yii\helpers\Html; use yii\helpers\Url; use yii\widgets\ActiveForm; $form = ActiveForm::begin(['enableAjaxValidation' => false, 'options' => ['enctype' => 'multipart/form-data', 'class' => 'model-form ']]); ?> <?php if ($model->value) { ?> <p><img src="<?php echo Image::thumb($model->value, 240); ?> "></p> <p> <a href="<?php echo Url::to(['/admin/settings/clear-image', 'id' => $model->primaryKey]); ?> " class="text-danger confirm-delete" title="<?php echo Yii::t('easyii', 'Remove logo'); ?> "> <i class="glyphicon glyphicon-remove"></i> <?php echo Yii::t('easyii', 'Remove logo'); ?> </a> </p> <?php } else {