public function get() { if (empty($this->src)) { if (empty($this->dummy)) { return ''; } $this->src = $this->dummy; } $options = ['class' => $this->_class, 'alt' => $this->template->replace($this->alt), 'title' => $this->title]; $src = $this->imageProvider->get($this->src, $this->w, $this->h); if (!((int) $this->const & ThumbInterface::WITHOUT_WIDTH_HEIGHT)) { $options['width'] = $this->imageProvider->width; $options['height'] = $this->imageProvider->height; } return (int) $this->const & ThumbInterface::OUTPUT_IMG ? Html::img($src, $options) : $src; }
/** * Renders the widget. */ public function run() { if ($this->hasModel() && $this->activeField) { $this->options = $this->activeField->calculateClientInputOption($this->options); $input = ActiveHtml::activeTextInput($this->model, $this->attribute, $this->options); } else { $input = Html::textInput($this->name, $this->value, $this->options); } if ($this->output === self::BASE64) { $src = $this->captcha->getDataUri(); } else { $src = Url::modify([$this->captchaAction, 'v' => uniqid()], Url::ABS); } $image = Html::img($src, $this->imageOptions); echo strtr($this->template, ['{input}' => $input, '{image}' => $image]); }
/** * Get thumb. * * @param string $path src to image * @param array $params params: * * - type: get `src`, `<a>`, `<img>` (default: `<img>`) * - w: width * - h: height * - q: quality * - class: attr `class` * - alt: attr `alt` * - const * - dummy * @param Template $template * @return string * @throws \rock\helpers\InstanceException */ public static function thumb($path, array $params, Template $template) { if (empty($path)) { if (empty($params['dummy'])) { return ''; } $path = $params['dummy']; } $const = Helper::getValue($params['const'], 1, true); /** @var ImageProvider $imageProvider */ $imageProvider = Instance::ensure(isset($params['imageProvider']) ? $params['imageProvider'] : 'imageProvider'); $src = $imageProvider->get($path, Helper::getValue($params['w']), Helper::getValue($params['h'])); if (!($const & ThumbInterface::WITHOUT_WIDTH_HEIGHT)) { $params['width'] = $imageProvider->width; $params['height'] = $imageProvider->height; } unset($params['h'], $params['w'], $params['type'], $params['const']); if (!empty($params['alt'])) { $params['alt'] = $template->replace($params['alt']); } return $const & ThumbInterface::OUTPUT_IMG ? Html::img($src, $params) : $src; }