Info |
---|
FieldType Field Type identifier: |
Table of Contents |
---|
The image FieldType Image Field Type allows you to store an image file.
A variation service handles conversion of the original image into different formats and sizes through a set of pre-configured preconfigured named variations: large, small, medium, black & white thumbnail, etc...
Value object
The value
property of an Image Field will return an \eZ\Publish\Core\FieldType\Image\Value
object with the following properties:
Property | Type | Example | Description |
---|---|---|---|
id | string | 0/8/4/1/1480-1-eng-GB/image.png | The image's unique identifier. Usually the path, or a part of the path. To get the full path, use |
alternativeText | string | This is a piece of text | The alternative text, as entered in the fieldField's properties |
fileName | string | image.png | The original image's filename, without the path |
fileSize | int | 37931 | The original image's size, in bytes |
uri | string | var/ezdemo_site/storage/images/0/8/4/1/1480-1-eng-GB/image.png | The original image's URI |
imageId | string | 240-1480 | A special image ID, used by REST |
...
Property | Type | Example | Description |
---|---|---|---|
width | int | 640 | The variation's width in pixels |
height | int | 480 | The variation's height in pixels |
name | string | medium | The variation's identifier |
info | mixed | Extra info, such as EXIF data | |
fileSize | int | ||
mimeType | string | ||
fileName | string | ||
dirPath | string | ||
uri | string | The variation's uri | |
lastModified | DateTime | When the variation was last modified |
FieldType Field Type options
The Image FieldType Field Type supports one FieldDefinition option: the maximum size for the file.
...
Info | ||
---|---|---|
| ||
From 5.2 version, new images must be inputed input using the The keys |
...
Children of the fieldValue node will list the general properties of the Field's original image (fileSize, fileName, inputUri, etc...), as well as variations. For each variation, an a uri is provided. Requested through REST, this resource will generate the variation if it doesn't exist yet, and list the variation details:
...
The variation service, ezpublish.fieldType.ezimage.variation_service
, can can be used to generate/get variations for a Field. It expects a VersionInfo, the Image Field and the variation name, as a string (large
, medium
, etc...)
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
$variation = $imageVariationHandler->getVariation( $imageField, $versionInfo, 'large' ); echo $variation->uri; |
Manipulating image content
From PHP
As for any FieldtypeField Type, there are several ways to input content to a Field. For an Image, the quickest is to call setField()
on the ContentStruct:
...
In order to customize the Image's alternative texts, you must first get an Image\Value object, and set this property. For that, you can use the Image\Value::fromString()
method , that accepts the path to a local file:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
$createStruct = $contentService->newContentCreateStruct( $contentTypeService->loadContentType( 'image' ), 'eng-GB' ); $imageField = \eZ\Publish\Core\FieldType\Image\Value::fromString( '/tmp/image.png' ); $imageField->alternativeText = 'My alternative text'; $createStruct->setField( 'image', $imageField ); |
You can also provide an a hash of Image\Value
properties, either to setField()
, or to the constructor:
...