Skip to content

Commit

Permalink
add width & heigth to the media field
Browse files Browse the repository at this point in the history
  • Loading branch information
zero-24 committed Sep 23, 2020
1 parent c7274b8 commit f4ff3bb
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions plugins/fields/media/tmpl/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
defined('_JEXEC') or die;

use Joomla\CMS\Image\Image;

if ($field->value == '')
{
return;
Expand All @@ -26,13 +28,17 @@

if ($value)
{
$path = $value['imagefile'];
$alt = ' alt="' . htmlentities($value['alt_text'], ENT_COMPAT, 'UTF-8', true) . '"';
$alt = ' alt="' . htmlentities($value['alt_text'], ENT_COMPAT, 'UTF-8', true) . '"';
$imagePath = htmlentities($value['imagefile'], ENT_COMPAT, 'UTF-8', true);

if (file_exists($path))
if (file_exists($imagePath))
{
$buffer .= sprintf('<img loading="lazy" src="%s"%s%s>',
htmlentities($path, ENT_COMPAT, 'UTF-8', true),
$imageInfo = Image::getImageFileProperties($imagePath);

$buffer .= sprintf('<img loading="lazy" width="%s" height="%s" src="%s"%s%s>',
$imageInfo->width,
$imageInfo->height,
$imagePath,
$class,
$alt
);
Expand Down

0 comments on commit f4ff3bb

Please sign in to comment.