jhealey5
12/14/2018 - 10:39 AM

Statamic image helper

Loads cms images/svgs inline

public function image()
    {
      $img = Asset::find($this->getParam('id'));
      $retina = $this->getParam('retina');

      if ($img->extension() == 'svg') {
        return File::get($img->resolvedPath());
      }

      $width = $retina ? $img->width() / 2 : $img->width();
      $height = $retina ? $img->height() / 2 : $img->height();

      return '<img src="' . $img->url() . '" width="'. $width .'" height="'. $height .'" alt="'. $img->get('alt') .'" />';
    }