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 |
|
DEFAULT_API_VERSION |
|
API_KEY_HEADER |
|
API_VERSION_HEADER |
|
SOURCEIMAGE_RESOURCE |
|
DYNAMIC_META_RESOURCE |
|
USER_META_RESOURCE |
|
STACK_RESOURCE |
|
OPERATIONS_RESOURCE |
|
Properties
protected ClientInterface | $client | Client to access Rokka. |
from Base |
protected string|null | $defaultOrganization | Default organization. |
from Base |
Methods
Constructor.
Call the API rokka endpoint.
Return the organization or the default if empty.
Upload a source image.
Upload a source image.
Delete a source image.
Restore a source image.
Copy a source 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.
List operations.
Create a stack.
List stacks.
Delete a stack.
Add the given DynamicMetadata to a SourceImage.
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.
Returns url for accessing the image.
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)
Constructor.
in
Base at line 68
setCredentials(string $key)
Set the credentials.
in
Base at line 85
protected ResponseInterface
call(string $method, string $path, array $options = [], bool $needsCredentials = true)
Call the API rokka endpoint.
in
Base at line 105
protected string
getOrganizationName(string|null $organization = null)
Return the organization or the default if empty.
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.
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(null|int $limit = null, null|int|string $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.
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(null|int $limit = null, null|int $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.
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.
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.
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.
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.
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.
UriInterface
getSourceImageUri(string $hash, string|StackUri $stack, string $format = 'jpg', string $name = null, string $organization = null)
Returns url for accessing the image.
protected string|false
extractHashFromLocationHeader(array $headers)
Helper function to extract from a Location header the image hash, only the first Location is used.