TemplateHelper
class TemplateHelper (View source)
This class provides lots of helper functionality usually used in templates.
It can also manage looking up hashes and uploading images to rokka, see the docs for details.
Methods
No description
Gets the rokka URL for an image Uploads it, if we don't have a hash locally.
Return the rokka URL for getting a resized image.
Return the rokka URL for getting a resized and cropped image.
Return the rokka URL for getting the image in it's original size.
Returns a src and srcset attibrute (as one string) with the correct rokka render urls for responsive images.
Returns a background-image:url defintions (as one string) with the correct rokka render urls for responsive images.
Gets the rokka URL for an image hash and stack with optional seo filename in the URL.
Gets the rokka image client used by this class.
Create a URL-safe text from $text.
Returns a LocalImage object depending on the input.
Details
__construct(string $organization, string $apiKey, AbstractCallbacks $callbacks = null, string|null $publicRokkaDomain = null, string|array|null $options = [])
No description
string|null
getHashMaybeUpload(AbstractLocalImage $image)
Returns the hash of an image.
If we don't have an image stored locally, it uploads it to rokka.
string
getStackUrl(AbstractLocalImage|string|SplFileInfo $image, string $stack, string|null $format = 'jpg', string|null $seo = null, string|null $seoLanguage = 'de')
Gets the rokka URL for an image Uploads it, if we don't have a hash locally.
string
getResizeUrl(AbstractLocalImage|string|SplFileInfo $image, string|int $width, string|int|null $height = null, string $format = 'jpg', string|null $seo = null, string $seoLanguage = 'de')
Return the rokka URL for getting a resized image.
string
getResizeCropUrl(AbstractLocalImage|string|SplFileInfo $image, string|int $width, string|int $height, string $format = 'jpg', string|null $seo = null, string $seoLanguage = '')
Return the rokka URL for getting a resized and cropped image.
string
getOriginalSizeUrl(AbstractLocalImage|string|SplFileInfo $image, string $format = 'jpg', string|null $seo = null, string $seoLanguage = '')
Return the rokka URL for getting the image in it's original size.
static string
getSrcAttributes(string $url, array $sizes = ['2x'])
Returns a src and srcset attibrute (as one string) with the correct rokka render urls for responsive images.
To be used directly in your HTML templates.
static string
getBackgroundImageStyle(string $url, array $sizes = ['2x'])
Returns a background-image:url defintions (as one string) with the correct rokka render urls for responsive images.
To be used directly in your CSS templates or HTML tags.
string
getImagename(AbstractLocalImage $image = null)
Returns the filename of the image without extension.
string
generateRokkaUrl(string $hash, string|StackUri $stack, string|null $format = 'jpg', string|null $seo = null, string|null $seoLanguage = 'de')
Gets the rokka URL for an image hash and stack with optional seo filename in the URL.
Doesn't upload it, if we don't have a local hash for it. Use getStackUrl for that.
Image
getRokkaClient()
Gets the rokka image client used by this class.
static string
slugify(string $text, string $language = 'de')
Create a URL-safe text from $text.
AbstractLocalImage
getImageObject(AbstractLocalImage|string|SplFileInfo $input, string|null $identifier = null, mixed $context = null)
Returns a LocalImage object depending on the input.
If input is
- LocalImageAbstract: returns that, sets $identidier and $context, if set
- SplFileInfo: returns \Rokka\Client\LocalImage\FileInfo
- string with hash pattern (/^[0-9a-f]{6,40}$/): returns \Rokka\Client\LocalImage\RokkaHash
- other strings: returns \Rokka\Client\LocalImage\FileInfo with $input as the path to the image