Summary: Talk page for AttachImageSize.
Maintainer: Petko
Users: (View? / Edit)

This space is for User-contributed commentary and notes. Please include your name and a date along with your comment.

I extended the original code, so it links webp-Images if they are available.
As I am not sure if this is a good way to propose kind of a fork, I posted it here under the Talk.
--Daniel Gross 2022-05-06

function LinkImgSrc($pagename, $imap, $path, $alt, $txt, $fmt=NULL) {
    global $FmtV, $UploadFileFmt, $UploadUrlFmt, $UploadPrefixFmt;
    if(!preg_match('/\\.(gif|jpe?g|png|webp)$/i', $path)) 
      return LinkUpload($pagename, $imap, $path, $alt, $txt, $fmt);
    if (preg_match('!^(.*)/([^/]+)$!', $path, $match)) {
      $pagename = MakePageName($pagename, $match[1]);
      $path = $match[2];
    $upname = MakeUploadName($pagename, $path);
    $filepath = FmtPageName("$UploadFileFmt$UploadPrefixFmt$upname", $pagename);
    $s = @getimagesize($filepath);
    $FmtV['$ImageSize'] = @$s[3];
    $uploadurl = FmtPageName("{$UploadUrlFmt}$UploadPrefixFmt/$upname", $pagename);
    $srcset = array();
    if (file_exists($filepath.'.webp'))    $srcset[] = "{$uploadurl}.webp 1x <!-- $uploadurl -->"; 
    if (file_exists($filepath.'@2x.webp')) $srcset[] = "{$uploadurl}@2x.webp 2x";
    if (count($srcset) > 0) $FmtV['$SrcSet'] = '<source srcset="'.implode(',',$srcset).'" type="image/webp">';
    $r = LinkUpload($pagename, $imap, $path, $alt, $txt, $fmt);
    $FmtV['$ImageSize'] = '';
    $FmtV['$SrcSet'] = '';
    return $r;
$LinkFunctions['Attach:'] = 'LinkImgSrc';
$ImgTagFmt = "<picture>\$SrcSet<img src='\$LinkUrl' alt='\$LinkAlt' title='\$LinkAlt' \$ImageSize></picture>";
$FmtV['$ImageSize'] = '';
$FmtV['$SrcSet'] = '';

Thank you for this, I have added a link from the recipe page to this one. --Petko

Talk page for the AttachImageSize recipe (users?).