class ImageTag extends BaseImageTag

Generates an HTML <img> tag with the src attribute set to the transformation URL, optional srcset and other specified attributes.

Properties

Configuration $config from BaseTag
Image $image from BaseImageTag
SrcSet $srcset from BaseImageTag
ImageTransformation $additionalTransformation from BaseImageTag

Methods

__construct(string|Image $source, Configuration|string|array|null $configuration = null, ImageTransformation $additionalTransformation = null)

BaseImageTag constructor.

configuration(Configuration|string|array|null $configuration)

Sets the configuration.

importConfiguration(Configuration|string|array|null $configuration)

Imports (merges) the configuration.

addClass(string|array $class)

Adds a tag class.

setClass(string|array $class)

Resets tag classes and sets the specified one.

setAttribute(string $key, mixed $value = null)

Sets tag attribute.

setAttributes(array $attributes)

Sets (multiple) tag attributes.

deleteAttribute(string $key)

Deletes tag attribute.

addContent(mixed $content, mixed $key = null)

Adds tag content.

setContent(mixed $content)

Sets the content of the tag to the specified one.

serialize()

Serializes the tag to string.

serializeContent(array $additionalContent = [], bool $prependAdditionalContent = false)

Serializes the tag content.

serializeAttributes(array $attributes = [])

Serializes the tag attributes.

toTag()

Serializes the tag to string.

__toString()

Serializes the tag to string.

upload(string $publicId, Configuration|string|array|null $configuration = null)

Static builder for uploaded asset image tag.

fetch(string $url, Configuration|string|array|null $configuration = null)

Static builder for fetch image tag (from URL).

facebook(string $facebookId, Configuration|string|array|null $configuration = null)

Static builder for facebook profile picture tag.

gravatar(string $email, Configuration|string|array|null $configuration = null)

Static builder for gravatar profile picture tag.

twitter(string $userId, Configuration|string|array|null $configuration = null)

Static builder for twitter profile picture tag.

twitterName(string $username, Configuration|string|array|null $configuration = null)

Static builder for twitter profile picture by name.

youTube(string $videoId, Configuration|string|array|null $configuration = null)

Static builder for the thumbnail of the YouTube video.

hulu(string $videoId, Configuration|string|array|null $configuration = null)

Static builder for the thumbnail of the YouTube video.

vimeo(string $videoId, Configuration|string|array|null $configuration = null)

Static builder for the thumbnail of the Vimeo video.

animoto(string $videoId, Configuration|string|array|null $configuration = null)

Static builder for the thumbnail of the animoto video.

worldStarHipHop(string $videoId, Configuration|string|array|null $configuration = null)

Static builder for the thumbnail of the World Star Hip Hop video.

dailyMotion(string $videoId, Configuration|string|array|null $configuration = null)

Static builder for the thumbnail of the DailyMotion video.

sprite(string $tag, Configuration|string|array|null $configuration = null)

Static builder for sprite tag.

cdnSubdomain(bool $cdnSubdomain = true)

Whether to automatically build URLs with multiple CDN sub-domains.

secureCdnSubdomain(bool $secureCdnSubdomain = true)

Whether to use secure CDN sub-domain.

cname(string $cname)

The custom domain name to use for building HTTP URLs.

secure(bool $secure = true)

Force HTTPS URLs for resources even if they are embedded in non-secure HTTP pages.

secureCname(string $secureCname)

The domain name of the CDN distribution to use for building HTTPS URLs.

privateCdn(bool $privateCdn = true)

Set this parameter to true if you are an Advanced plan user with a private CDN distribution.

signUrl(bool $signUrl = true)

Set to true to create a signed Cloudinary URL.

longUrlSignature(bool $longUrlSignature = true)

Setting both this and signUrl to true will sign the URL using the first 32 characters of a SHA-256 hash.

shorten(bool $shorten = true)

Set to true to use shorten asset type.

useRootPath(bool $useRootPath = true)

Set to true to omit type and resource_type in the URL.

forceVersion(bool $forceVersion = true)

Set to false to omit default version string for assets in folders in the delivery URL.

analytics(bool $analytics = true)

Set to false to omit analytics.

fromParams(string $source, array $params = [])

Creates a new base image tag from the provided source and an array of parameters.

handleResponsive(array $params, Configuration $configuration)

No description

image(mixed $image, Configuration $configuration = null)

Sets the image.

jsonSerialize()

Serializes to json.

addTransformation(CommonTransformation $transformation)

Adds (appends) a transformation.

addAction(BaseAction|BaseQualifier|mixed $action)

Adds (chains) a transformation action.

breakpoints(array $breakpoints = null)

Explicitly sets the breakpoints.

autoOptimalBreakpoints(bool $autoOptimalBreakpoints = true)

Defines whether to use auto optimal breakpoints.

relativeWidth(float $relativeWidth = 1.0)

Sets the image relative width.

Details

__construct(string|Image $source, Configuration|string|array|null $configuration = null, ImageTransformation $additionalTransformation = null)

BaseImageTag constructor.

Parameters

Name Type Description
$source string|Image The Public ID or Image instance
$configuration Configuration|string|array|null The Configuration source.
$additionalTransformation ImageTransformation The additional transformation.

Configuration configuration(Configuration|string|array|null $configuration)

Sets the configuration.

Parameters

Name Type Description
$configuration Configuration|string|array|null The Configuration source.

Return Value

Configuration

BaseTag importConfiguration(Configuration|string|array|null $configuration)

Imports (merges) the configuration.

Parameters

Name Type Description
$configuration Configuration|string|array|null The Configuration source.

Return Value

BaseTag

BaseTag addClass(string|array $class)

Adds a tag class.

Parameters

Name Type Description
$class string|array The class to add.

Return Value

BaseTag

BaseTag setClass(string|array $class)

Resets tag classes and sets the specified one.

Parameters

Name Type Description
$class string|array The class to set.

Return Value

BaseTag

BaseTag setAttribute(string $key, mixed $value = null)

Sets tag attribute.

Parameters

Name Type Description
$key string The attribute name.
$value mixed The attribute value.

Return Value

BaseTag

BaseTag setAttributes(array $attributes)

Sets (multiple) tag attributes.

Parameters

Name Type Description
$attributes array The attributes to set.

Return Value

BaseTag

BaseTag deleteAttribute(string $key)

Deletes tag attribute.

Parameters

Name Type Description
$key string The name of the attribute to delete.

Return Value

BaseTag

$this addContent(mixed $content, mixed $key = null)

Adds tag content.

Parameters

Name Type Description
$content mixed The content value.
$key mixed Optional. Used for uniqueness.

Return Value

$this

BaseTag setContent(mixed $content)

Sets the content of the tag to the specified one.

Parameters

Name Type Description
$content mixed The content of the tag.

Return Value

BaseTag

string serialize()

Serializes the tag to string.

Return Value

string

string serializeContent(array $additionalContent = [], bool $prependAdditionalContent = false)

Serializes the tag content.

Parameters

Name Type Description
$additionalContent array The additional content.
$prependAdditionalContent bool Whether to prepend additional content (instead of append).

Return Value

string

string serializeAttributes(array $attributes = [])

Serializes the tag attributes.

Parameters

Name Type Description
$attributes array Optional. Additional attributes to add without affecting the tag state.

Return Value

string

string toTag()

Serializes the tag to string.

Return Value

string

string __toString()

Serializes the tag to string.

Return Value

string

static ImageTagDeliveryTypeTrait upload(string $publicId, Configuration|string|array|null $configuration = null)

Static builder for uploaded asset image tag.

Parameters

Name Type Description
$publicId string The public ID of the asset.
$configuration Configuration|string|array|null The Configuration source.

Return Value

ImageTagDeliveryTypeTrait

static ImageTagDeliveryTypeTrait fetch(string $url, Configuration|string|array|null $configuration = null)

Static builder for fetch image tag (from URL).

Parameters

Name Type Description
$url string
$configuration Configuration|string|array|null The Configuration source.

Return Value

ImageTagDeliveryTypeTrait

static ImageTagDeliveryTypeTrait facebook(string $facebookId, Configuration|string|array|null $configuration = null)

Static builder for facebook profile picture tag.

Parameters

Name Type Description
$facebookId string
$configuration Configuration|string|array|null The Configuration source.

Return Value

ImageTagDeliveryTypeTrait

static ImageTagDeliveryTypeTrait gravatar(string $email, Configuration|string|array|null $configuration = null)

Static builder for gravatar profile picture tag.

Parameters

Name Type Description
$email string
$configuration Configuration|string|array|null The Configuration source.

Return Value

ImageTagDeliveryTypeTrait

static ImageTagDeliveryTypeTrait twitter(string $userId, Configuration|string|array|null $configuration = null)

Static builder for twitter profile picture tag.

Parameters

Name Type Description
$userId string
$configuration Configuration|string|array|null The Configuration source.

Return Value

ImageTagDeliveryTypeTrait

static ImageTagDeliveryTypeTrait twitterName(string $username, Configuration|string|array|null $configuration = null)

Static builder for twitter profile picture by name.

Parameters

Name Type Description
$username string
$configuration Configuration|string|array|null The Configuration source.

Return Value

ImageTagDeliveryTypeTrait

static ImageTagDeliveryTypeTrait youTube(string $videoId, Configuration|string|array|null $configuration = null)

Static builder for the thumbnail of the YouTube video.

Parameters

Name Type Description
$videoId string
$configuration Configuration|string|array|null The Configuration source.

Return Value

ImageTagDeliveryTypeTrait

static ImageTagDeliveryTypeTrait hulu(string $videoId, Configuration|string|array|null $configuration = null)

Static builder for the thumbnail of the YouTube video.

Parameters

Name Type Description
$videoId string
$configuration Configuration|string|array|null The Configuration source.

Return Value

ImageTagDeliveryTypeTrait

static ImageTagDeliveryTypeTrait vimeo(string $videoId, Configuration|string|array|null $configuration = null)

Static builder for the thumbnail of the Vimeo video.

Parameters

Name Type Description
$videoId string
$configuration Configuration|string|array|null The Configuration source.

Return Value

ImageTagDeliveryTypeTrait

static ImageTagDeliveryTypeTrait animoto(string $videoId, Configuration|string|array|null $configuration = null)

Static builder for the thumbnail of the animoto video.

Parameters

Name Type Description
$videoId string
$configuration Configuration|string|array|null The Configuration source.

Return Value

ImageTagDeliveryTypeTrait

static ImageTagDeliveryTypeTrait worldStarHipHop(string $videoId, Configuration|string|array|null $configuration = null)

Static builder for the thumbnail of the World Star Hip Hop video.

Parameters

Name Type Description
$videoId string
$configuration Configuration|string|array|null The Configuration source.

Return Value

ImageTagDeliveryTypeTrait

static ImageTagDeliveryTypeTrait dailyMotion(string $videoId, Configuration|string|array|null $configuration = null)

Static builder for the thumbnail of the DailyMotion video.

Parameters

Name Type Description
$videoId string
$configuration Configuration|string|array|null The Configuration source.

Return Value

ImageTagDeliveryTypeTrait

static ImageTagDeliveryTypeTrait sprite(string $tag, Configuration|string|array|null $configuration = null)

Static builder for sprite tag.

Parameters

Name Type Description
$tag string
$configuration Configuration|string|array|null The Configuration source.

Return Value

ImageTagDeliveryTypeTrait

$this cdnSubdomain(bool $cdnSubdomain = true)

Whether to automatically build URLs with multiple CDN sub-domains.

Parameters

Name Type Description
$cdnSubdomain bool

Return Value

$this

See also

https://cloudinary.com/documentation/advanced_url_delivery_options#multiple_sub_domains

$this secureCdnSubdomain(bool $secureCdnSubdomain = true)

Whether to use secure CDN sub-domain.

Parameters

Name Type Description
$secureCdnSubdomain bool

Return Value

$this

$this cname(string $cname)

The custom domain name to use for building HTTP URLs.

Relevant only for Advanced plan users that have a private CDN distribution and a custom CNAME.

Parameters

Name Type Description
$cname string

Return Value

$this

See also

https://cloudinary.com/documentation/advanced_url_delivery_options#private_cdns_and_cnames

$this secure(bool $secure = true)

Force HTTPS URLs for resources even if they are embedded in non-secure HTTP pages.

Parameters

Name Type Description
$secure bool

Return Value

$this

$this secureCname(string $secureCname)

The domain name of the CDN distribution to use for building HTTPS URLs.

Relevant only for Advanced plan users that have a private CDN distribution.

Parameters

Name Type Description
$secureCname string The CNAME for secure (https) URLs.

Return Value

$this

See also

https://cloudinary.com/documentation/advanced_url_delivery_options#private_cdns_and_cnames

$this privateCdn(bool $privateCdn = true)

Set this parameter to true if you are an Advanced plan user with a private CDN distribution.

Parameters

Name Type Description
$privateCdn bool

Return Value

$this

See also

https://cloudinary.com/documentation/advanced_url_delivery_options#private_cdns_and_cnames

$this signUrl(bool $signUrl = true)

Set to true to create a signed Cloudinary URL.

Parameters

Name Type Description
$signUrl bool

Return Value

$this

$this longUrlSignature(bool $longUrlSignature = true)

Setting both this and signUrl to true will sign the URL using the first 32 characters of a SHA-256 hash.

Parameters

Name Type Description
$longUrlSignature bool

Return Value

$this

See also

https://cloudinary.com/documentation/advanced_url_delivery_options#generating_delivery_url_signatures

$this shorten(bool $shorten = true)

Set to true to use shorten asset type.

Parameters

Name Type Description
$shorten bool

Return Value

$this

$this useRootPath(bool $useRootPath = true)

Set to true to omit type and resource_type in the URL.

Parameters

Name Type Description
$useRootPath bool

Return Value

$this

See also

https://cloudinary.com/documentation/advanced_url_delivery_options#root_path_urls

$this forceVersion(bool $forceVersion = true)

Set to false to omit default version string for assets in folders in the delivery URL.

Parameters

Name Type Description
$forceVersion bool

Return Value

$this

$this analytics(bool $analytics = true)

Set to false to omit analytics.

Parameters

Name Type Description
$analytics bool Whether to include analytics.

Return Value

$this

static BaseImageTag fromParams(string $source, array $params = [])

Creates a new base image tag from the provided source and an array of parameters.

Parameters

Name Type Description
$source string The public ID of the asset.
$params array The asset parameters.

Return Value

BaseImageTag

static handleResponsive(array $params, Configuration $configuration)

Parameters

Name Type Description
$params array
$configuration Configuration

BaseImageTag image(mixed $image, Configuration $configuration = null)

Sets the image.

Parameters

Name Type Description
$image mixed The public ID or Image asset.
$configuration Configuration The configuration instance.

Return Value

BaseImageTag

mixed jsonSerialize()

Serializes to json.

Return Value

mixed

BaseImageTag addTransformation(CommonTransformation $transformation)

Adds (appends) a transformation.

Appended transformation is nested.

Parameters

Name Type Description
$transformation CommonTransformation The transformation to add.

Return Value

BaseImageTag

BaseImageTag addAction(BaseAction|BaseQualifier|mixed $action)

Adds (chains) a transformation action.

Parameters

Name Type Description
$action BaseAction|BaseQualifier|mixed The transformation action to add. If BaseQualifier is provided, it is wrapped with action.

Return Value

BaseImageTag

$this breakpoints(array $breakpoints = null)

Explicitly sets the breakpoints.

Parameters

Name Type Description
$breakpoints array The breakpoints.

Return Value

$this

$this autoOptimalBreakpoints(bool $autoOptimalBreakpoints = true)

Defines whether to use auto optimal breakpoints.

Parameters

Name Type Description
$autoOptimalBreakpoints bool Indicates whether to use auto optimal breakpoints.

Return Value

$this

$this relativeWidth(float $relativeWidth = 1.0)

Sets the image relative width.

Parameters

Name Type Description
$relativeWidth float The percentage of the screen that the image occupies..

Return Value

$this

Constants

SINGLE_QUOTES

DOUBLE_QUOTES

NAME

IS_VOID

BLANK

RESPONSIVE_CLASS

HI_DPI_CLASS