How to resize image in editor snippet?

How can i resize the image inside the editor snippet?

$src is a string not a fileobject. Its the path to the image in de media folder not to the page dir.

<?php if ($block->isNotEmpty()): ?>
<figure<?= attr(['class' => $attrs->css()->value()], ' ') ?>>
  <?php if ($attrs->link()->isNotEmpty()): ?>
  <a href="<?= $attrs->link()->toUrl() ?>">
    <img src="<?= $src ?>" alt="<?= $attrs->alt() ?>">
  </a>
  <?php else: ?>
  <img src="<?= $src ?>" alt="<?= $attrs->alt() ?>">
  <?php endif ?>

  <?php if ($attrs->caption()->isNotEmpty()): ?>
  <figcaption>
    <?= $attrs->caption() ?>
  </figcaption>
  <?php endif ?>
</figure>
<?php endif ?>
2 Likes

Sorry that I missed that post, thanks for helping out and the beautiful Newsletters!

1 Like

You can access the image object directly in the snippet like that:

<?php if ($block->isNotEmpty()): ?>
    <figure<?= attr(['class' => $attrs->css()->value()], ' ') ?>>
        <?php if ($attrs->link()->isNotEmpty()): ?>
            <a href="<?= $attrs->link()->toUrl() ?>">
                <?= $image->resize(300) ?>
            </a>
        <?php else: ?>
            <?= $image->resize(300) ?>
        <?php endif ?>

        <?php if ($attrs->caption()->isNotEmpty()): ?>
            <figcaption>
                <?= $attrs->caption() ?>
            </figcaption>
        <?php endif ?>
    </figure>
<?php endif ?>
1 Like

Hi, thank you for this. And how can I set the alt tag?

You are posting in a very old thread. Are you referring to the now archived Editor plugin or the blocks field?

Hallo texnixe,
ich nutze das Editor Plugin und habe im Snippet wie oben beschrieben den Code benutzt, hab aber leider keine Idee wie ich den alt Tag jetzt reinbekomme.

That would be $attrs->alt().

But please keep in mind that the Editor plugin is no longer supported and you might want to consider using the blocks/layout fields instead.

Please also note that the forum language is English.