/** * Get an img html tag for the image in the specified size * * @param Image|string $image Either an instance of Image or the file_path * @param string $size * @param int|null $width * @param int|null $height * @return string */ public function getHtml($image, $size = 'original', $width = null, $height = null) { if ($image instanceof Image) { if (null == $image->getFilePath()) { return ''; } $aspectRatio = $image->getAspectRatio(); if (null !== $width && null == $height && $aspectRatio !== null) { $height = round($width / $aspectRatio); } if (null !== $height && null == $width && $aspectRatio !== null) { $width = round($height * $aspectRatio); } if (null == $width) { $width = $image->getWidth(); } if (null == $height) { $height = $image->getHeight(); } } return sprintf('<img src="%s" width="%s" height="%s" />', $this->getUrl($image, $size), $width, $height); }