This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I'm trying to display exif meta data for pictures that are outputed with for loop inside markup section.
I managed to display exif meta data of single picture
This code section for single picture:
function onEnd()
{
$image_file = 'storage/app/media/2020/image01.jpg';
$exif = exif_read_data($image_file, 0, true);
$this['filename'] = $exif['IFD0']['Model'];
}
Markup for single picture
Filename: {{filename}}
This code section for multiple pictures:
use Cms\Classes\Theme;
function onEnd () { //must use onEnd as at this moment all components are initialized properly
// accessing component from $this->components with alias name and get its details
$frontId = $this->components['builderDetails']->record->id;
// now slots variable are available in Markup section
$this["galerijaLink"] = Db::table('foto_')->where('id', $frontId)->value('gallery_folder');
$galerijaLink = Db::table('foto_')->where('id', $frontId)->value('gallery_folder');
$items = [ ];
$files = File::allFiles( 'storage/app/media/' .$galerijaLink. '/' );
foreach ($files as $item) {
$items[] = $item->getFilename();
$this['slike'] = $items;
$image_file = $item;
$exif = exif_read_data($image_file, 0, true);
$this["filename"] = $exif["FILE"]["FileName"];
}
sort($items, SORT_NUMERIC); // Bigest file number first
$this['gallery'] = $items;
Markup for multiple pictures
{% set record = builderDetails.record %}
{% set displayColumn = builderDetails.displayColumn %}
{% set notFoundMessage = builderDetails.notFoundMessage %}
{% if record %}
{% for image in gallery %}
{% set path = '/storage/app/media' %}
{% set gallerySlug = record.gallery_folder %}
{% set tilda = '/' %}
{% set combinedLink = path ~ gallerySlug ~ tilda ~ image %}
<div class="grid-item">
<a href="{{combinedLink}}" target="_blank"><img src="{{combinedLink | resize(1000)}}" alt="{{filename}}" /></a>
</div>
{% endfor %}
{% endif %}
My problem is that I get the same filename inside alt atribute on every picture. For example its alt="image03.jpg" on every single iterated picture. Is there any possible solution for this for loop output or could this for loop output be done inside code section?
Here's a test CMS page to demonstrate how that should be done:
title = Example
url = exif
==
<?php
function onEnd()
{
$items = [];
foreach (File::allFiles( 'storage/app/media/') as $item) {
$items[] = [
'file' => $item,
'exif' => @exif_read_data($item, 0, true),
];
}
$this['gallery'] = $items;
}
==
<ul>
{% for image in gallery %}
<li>{{ image.exif.FILE.FileName|default('No Exif Data') }}</li>
{% endfor %}
</ul>
Hope that helps!
You can check now working example here: Gallery example
Enabled only inside sport category when you hover over image.
Last updated
1-5 of 5