Image
class Image extends Base (View source)
Image client for the rokka.io service.
All code examples assume you already have a Rokka Image Client in $client with:
$client = \Rokka\Client\Factory::getImageClient('testorganization', 'apiKey'); Constants
| DEFAULT_API_BASE_URL |
|
| protected DEFAULT_API_VERSION |
|
| protected API_KEY_HEADER |
|
| protected API_AUTHORIZATION_HEADER |
|
| protected API_VERSION_HEADER |
|
| private SOURCEIMAGE_RESOURCE |
|
| private DYNAMIC_META_RESOURCE |
|
| private USER_META_RESOURCE |
|
| private STACK_RESOURCE |
|
| private OPERATIONS_RESOURCE |
|
| private ALIAS_RESOURCE |
|
Properties
| protected ClientInterface | $client | Client to access Rokka. |
from Base |
| protected string|null | $defaultOrganization | Default organization. |
from Base |
Methods
Constructor.
Get the API Token Payload (unverified).
Returns for how many seconds a token is valid for.
Call the API rokka endpoint.
Return the organization or the default if empty.
Gets the payload of an API JWT Token (not validated against the signature).
Upload a source image.
Upload a source image.
Delete a source image.
Restore a source image.
Copy a source image to another org.
Copy multiple sources image to another org.
Delete source images by binaryhash.
Search and list source images.
List source images.
Load a source image's metadata from Rokka.
Loads source images metadata from Rokka by binaryhash.
Get a source image's binary contents from Rokka.
Download multiple source images as a ZIP archive.
List operations.
Create a stack.
List stacks.
Delete a stack.
Purge a stack from the CDN cache.
List the available stack options as a JSON schema document.
Sign a render URL via the Rokka API.
Add the given DynamicMetadata to a SourceImage.
(Un)sets protected status to a SourceImage.
(Un)sets locked status to a SourceImage.
Rename a source image.
Purge a source image from the CDN cache.
Get the source image alias for the given name.
Create or overwrite an alias that maps a name to a source image hash.
Delete the alias mapping (does not invalidate the CDN cache; call {Image::deleteSourceImageAliasCache()} for that).
Purge an alias from the CDN cache.
No description
No description
Delete the given DynamicMetadata from a SourceImage.
Add (or update) the given user-metadata field to the image.
Add the given fields to the user-metadata of the image.
Set the given fields as the user-metadata of the image.
Delete the user-metadata from the given image.
Delete the given field from the user-metadata of the image.
Delete the given fields from the user-metadata of the image.
Get all user-metadata for an image.
Get a single user-metadata field for an image.
Returns url for accessing the image.
No description
No description
Helper function to extract from a Location header the image hash, only the first Location is used.
Details
__construct(ClientInterface $client, string|null $defaultOrganization, string $apiKey, string|null $apiToken = null)
Constructor.
in
Base at line 71
void
setCredentials(string|null $key)
Set the credentials.
in
Base at line 83
void
setToken(string|null $token)
Set the API Token.
in
Base at line 93
string|null
getToken()
Get the API Token.
in
Base at line 103
array|null
getTokenPayload(string|null $token = null)
Get the API Token Payload (unverified).
in
Base at line 124
int
getTokenIsValidFor(string|null $token = null)
Returns for how many seconds a token is valid for.
Doesn't check for other validity (like ip restrictions)
Returns -1 if there's no token
in
Base at line 150
protected ResponseInterface
call(string $method, string $path, array $options = [], bool $needsCredentials = true, array $credentials = [])
Call the API rokka endpoint.
in
Base at line 176
protected string
getOrganizationName(string|null $organization = null)
Return the organization or the default if empty.
in
Base at line 189
protected array|null
getUnvalidatedPayload(string $token)
Gets the payload of an API JWT Token (not validated against the signature).
SourceImageCollection
uploadSourceImage(string $contents, string $fileName, string $organization = '', array|null $options = null)
Upload a source image.
SourceImageCollection
uploadSourceImageByUrl(string $url, string $organization = '', array|null $options = null)
Upload a source image.
bool
deleteSourceImage(string $hash, string $organization = '')
Delete a source image.
bool
restoreSourceImage(string $hash, string $organization = '')
Restore a source image.
bool
copySourceImage(string $hash, string $destinationOrg, bool $overwrite = true, string $sourceOrg = '')
Copy a source image to another org.
Needs read permissions on the source organization and write permissions on the write organization.
array
copySourceImages(array $hashes, string $destinationOrg, bool $overwrite = true, string $sourceOrg = '')
Copy multiple sources image to another org.
Needs read permissions on the source organization and write permissions on the write organization.
bool
deleteSourceImagesWithBinaryHash(string $binaryHash, string $organization = '')
Delete source images by binaryhash.
Since the same binaryhash can have different images in rokka, this may delete more than one picture.
SourceImageCollection
searchSourceImages(array $search = [], array $sorts = [], int|null $limit = null, int|string|null $offset = null, string $organization = '')
Search and list source images.
Sort direction can either be: "asc", "desc" (or the boolean TRUE value, treated as "asc")
SourceImageCollection
listSourceImages(int|null $limit = null, int|string|null $offset = null, string $organization = '')
deprecated
deprecated
List source images.
SourceImage
getSourceImage(string $hash, string $organization = '')
Load a source image's metadata from Rokka.
SourceImageCollection
getSourceImagesWithBinaryHash(string $binaryHash, string $organization = '')
Loads source images metadata from Rokka by binaryhash.
Since the same binaryhash can have different images in rokka, this may return more than one picture.
string
getSourceImageContents(string $hash, string $organization = '')
Get a source image's binary contents from Rokka.
string
downloadSourceImagesAsZip(int|null $limit = null, int|string|null $offset = null, array $sorts = [], bool $deleted = false, string $organization = '')
Download multiple source images as a ZIP archive.
The server enforces a maximum of 300 images per request. Use the same $sorts shape as
{\Rokka\Client\Image::searchSourceImages()} (e.g. ['created' => 'desc']).
OperationCollection
listOperations()
List operations.
Stack
createStack(string $stackName, array $stackOperations, string $organization = '', array $stackOptions = [], bool $overwrite = false)
deprecated
deprecated
Create a stack.
Stack
saveStack(Stack $stack, array $requestConfig = [])
Save a stack on rokka.
Example:
$stack = new Stack(null, 'teststack');
$stack->addStackOperation(new StackOperation('resize', ['width' => 200, 'height' => 200]));
$stack->addStackOperation(new StackOperation('rotate', ['angle' => 45]));
$stack->setStackOptions(['jpg.quality' => 80]);
$requestConfig = ['overwrite' => true];
$stack = $client->saveStack($stack, $requestConfig);
echo 'Created stack ' . $stack->getName() . PHP_EOL;
The only requestConfig option currently can be ['overwrite' => true|false] (false is the default)
StackCollection
listStacks(int|null $limit = null, int|null $offset = null, string $organization = '')
List stacks.
use Rokka\Client\Core\Stack;
$client = \Rokka\Client\Factory::getImageClient('testorganization', 'apiKey');
$stacks = $client->listStacks();
foreach ($stacks as $stack) {
echo 'Stack ' . $stack->getName() . PHP_EOL;
}
Stack
getStack(string $stackName, string $organization = '')
Return a stack.
bool
deleteStack(string $stackName, string $organization = '')
Delete a stack.
bool
deleteStackCache(string $stackName, string $organization = '')
Purge a stack from the CDN cache.
Pass '*' as the stack name to invalidate the entire organization's cache.
Limited to 5 invocations per hour. Larger orgs are blocked from using this — clear stack
names with deleteStack/createStack are the preferred approach.
array<string, mixed>
listStackOptions()
List the available stack options as a JSON schema document.
Useful for introspecting what option keys, types, and defaults the Rokka API accepts on stack creation. The response is the raw JSON schema as an associative array.
array<string, mixed>
signUrlOnServer(string $url, string|null $signKey = null, DateTime|null $until = null, int|null $roundDateUpTo = null, string $organization = '')
Sign a render URL via the Rokka API.
The same signing algorithm is available client-side via {\Rokka\Client\UriHelper::signUrl()}, which is generally preferable since it requires no network round-trip. Use this method when you want the API to sign with the organization's stored signing key rather than supplying the key locally.
string|false
setDynamicMetadata(DynamicMetadataInterface|array $dynamicMetadata, string $hash, string $organization = '', array $options = [])
Add the given DynamicMetadata to a SourceImage.
Returns the new Hash for the SourceImage, it could be the same as the input one if the operation did not change it.
Supported options:
['deletePrevious' => true]— deletes the previous image from rokka (but not the binary, since that's still used). If not set, the original image is kept in rokka.['keepHash' => true]— FOOTGUN. Updates the metadata in place without changing the image hash. Downstream caches (CloudFront, memcached, browser) will keep serving stale renders until manually invalidated. Mutually exclusive withdeletePrevious. When passing multiple metadata entries, all entries are written to the same (unchanged) hash.
string|false
setProtected(bool $protected, string $hash, string $organization = '', array $options = [])
(Un)sets protected status to a SourceImage.
Returns the new Hash for the SourceImage, it could be the same as the input one if the operation did not change the protected status.
The only option currently can be ['deletePrevious' => true]
which deletes the previous image from rokka (but not the binary, since that's still used) If not set, the original image is kept in rokka.
SourceImage
setLocked(bool $locked, string $hash, string $organization = '')
(Un)sets locked status to a SourceImage.
bool
setSourceImageName(string $name, string $hash, string $organization = '')
Rename a source image.
array<int, string>
deleteSourceImageCache(string $hash, string $organization = '')
Purge a source image from the CDN cache.
Only available on paid accounts. Free accounts will receive a 403 response.
SourceImageAlias
getSourceImageAlias(string $alias, string $organization = '')
Get the source image alias for the given name.
SourceImageAlias
setSourceImageAlias(string $alias, string $hash, string $organization = '', array $options = [])
Create or overwrite an alias that maps a name to a source image hash.
The only option currently accepted is ['overwrite' => true], which allows replacing
an existing alias. Without it, the call fails if the alias already exists.
bool
deleteSourceImageAlias(string $alias, string $organization = '')
Delete the alias mapping (does not invalidate the CDN cache; call {Image::deleteSourceImageAliasCache()} for that).
array<int, string>
deleteSourceImageAliasCache(string $alias, string $organization = '')
Purge an alias from the CDN cache.
Only available on paid accounts (rate-limited to 10 calls/hour).
SourceImage
addAutolabels(string $hash, string|null $organization = null)
No description
SourceImage
addAutodescription(string[] $languages, string $hash, string|null $organization = null, array $options = [])
No description
string|false
deleteDynamicMetadata(string $dynamicMetadataName, string $hash, string $organization = '', array $options = [])
Delete the given DynamicMetadata from a SourceImage.
Returns the new Hash for the SourceImage, it could be the same as the input one if the operation did not change it.
Supported options:
['deletePrevious' => true]— deletes the previous image from rokka (but not the binary, since that's still used). If not set, the original image is kept in rokka.['keepHash' => true]— FOOTGUN. Removes the metadata in place without changing the image hash. Downstream caches (CloudFront, memcached, browser) will keep serving stale renders until manually invalidated. Mutually exclusive withdeletePrevious.
bool
setUserMetadataField(string $field, string $value, string $hash, string $organization = '')
Add (or update) the given user-metadata field to the image.
bool
addUserMetadata(array $fields, string $hash, string $organization = '')
Add the given fields to the user-metadata of the image.
bool
setUserMetadata(array $fields, string $hash, string $organization = '')
Set the given fields as the user-metadata of the image.
bool
deleteUserMetadata(string $hash, string $organization = '')
Delete the user-metadata from the given image.
bool
deleteUserMetadataField(string $field, string $hash, string $organization = '')
Delete the given field from the user-metadata of the image.
bool
deleteUserMetadataFields(array $fields, string $hash, string $organization = '')
Delete the given fields from the user-metadata of the image.
array<string, mixed>
getUserMetadata(string $hash, string $organization = '')
Get all user-metadata for an image.
mixed|null
getUserMetadataField(string $field, string $hash, string $organization = '')
Get a single user-metadata field for an image.
UriInterface
getSourceImageUri(string $hash, string|StackUri $stack, string $format = 'jpg', string $name = null, string $organization = null)
Returns url for accessing the image.
void
setRenderBaseUrl(string|null $renderBaseUrl)
No description
string|null
getRenderBaseUrl()
No description
protected string|false
extractHashFromLocationHeader(array $headers)
Helper function to extract from a Location header the image hash, only the first Location is used.