/** * Render image item. * @return string */ protected function renderImage() { $thumb = $this->thumb; if ($thumb === null) { $thumb = $this->file; } list($w, $h) = getimagesize(Yii::getAlias('@webroot') . $thumb); list($width, $height) = ImageFile::getBounds($w, $h, $this->width, $this->height); $left = ($this->width - $width) / 2; $top = ($this->height - $height) / 2; $style = "width: {$width}px; height: {$height}px; left: {$left}px; top: {$top}px"; $image = Html::img($thumb, ['style' => $style]); return Html::a($image, $this->file, ['class' => 'uploadimage-image', 'style' => "width: {$this->width}px; height: {$this->height}px;"]); }