General

  eZ Systems Website
  Technical documentation
  Editor documentation

This Documentation contains:
 
Technical documentation:



⚠ WARNING ! This documentation is deprecated !

Please go to the current Technical Documentation

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

FieldType Field Type identifier: ezimage
Validators: File size
Value object: \eZ\Publish\Core\FieldType\Image\Value
Associated Services: ezpublish.fieldType.ezimage.variation_service

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:

PropertyTypeExampleDescription
idstring0/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 URI property.

alternativeTextstringThis is a piece of textThe alternative text, as entered in the fieldField's properties
fileNamestringimage.pngThe original image's filename, without the path
fileSizeint37931The original image's size, in bytes
uristringvar/ezdemo_site/storage/images/0/8/4/1/1480-1-eng-GB/image.pngThe original image's URI
imageIdstring240-1480A special image ID, used by REST

...

PropertyTypeExampleDescription
widthint640The variation's width in pixels
heightint480The variation's height in pixels
namestringmediumThe variation's identifier
infomixed Extra info, such as EXIF data
fileSizeint  
mimeTypestring  
fileNamestring  
dirPathstring  
uristring The variation's uri
lastModifiedDateTime 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
titleinputUri

From 5.2 version, new images must be inputed input using the inputUri property from Image\Value.

The keys id and path still work, but a deprecation warning will be thrown.

...

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
languagephp
typephp
linenumberstrue
$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
languagephp
typephp
linenumberstrue
$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:

...