/** * Modify thumbnail DOM * @param ThumbnailImage $thumbnail * @param array $attribs Attributes of the <img> element * @param array|boolean $linkAttribs Attributes of the wrapping <a> element */ public static function thumbnailBeforeProduceHTML(ThumbnailImage $thumbnail, array &$attribs, &$linkAttribs) { $file = $thumbnail->getFile(); if ($file) { // At the moment all classes that extend File have getWidth() and getHeight() // but since the File class doesn't have these methods defined, this check // is more future-proof if (method_exists($file, 'getWidth')) { $attribs['data-file-width'] = $file->getWidth(); } if (method_exists($file, 'getHeight')) { $attribs['data-file-height'] = $file->getHeight(); } } return true; }
/** * Adds data attribute to standard image output * @param ThumbnailImage $thumbnail * @param array $attribs * @param array $linkAttribs * @return boolean */ public function onThumbnailBeforeProduceHTML($thumbnail, &$attribs, &$linkAttribs) { $oFile = $thumbnail->getFile(); $linkAttribs['data-bs-filename'] = $oFile->getName(); $linkAttribs['data-bs-fileurl'] = $oFile->getUrl(); return true; }