Metadata of selected image

Hello,

I have a blueprint like that :

files:
  fields:
    data_height:
       label: Hauteur
       type: number
       step: .1
       width: 1/3
    data_width:
       label: Largeur
       type: number
       step: .1
       width: 1/3
   data_depth:
       label: Profondeur
      type: number
      step: .1
      width: 1/3
   data_medium:
      label: Medium
      type: text
   data_date:
     label: Date
     type: text
     width: 1/3
   data_lieu:
     label: Lieu
     type: text
     width: 2/3

fields:
  first:
    label: First image
    type: image
    width: 1/2

And I want to echo the metadata of this image to, but when I do something like $page->first()->data_height() I just have the name of the image.

You need a File object first, the field just contains the filename. With the toFile() field method, you can create a File object from the filename stored in the field:

if($image = $page->first()->toFile()):
  echo $image->data_height();
endif

The if statement is important here because the file might have been related or renamed after we stored the filename. Or the field might be empty. In both cases, we wouldn’t get a File object and the call to metadata would throw an error.

Yeah it runs, thank you !