New Asset: cant create thumb

I’m generating watermarked images of a page’s images and place them in a subfolder (without kirby methods, just vanilla php)


now I want to resize the watermarked image and get its url from media folder to use it in a template

I tried new Asset with absolute path of the new file and with a relative url like in this post:

when I dump $asset->resize(100) or just $asset

with absolute path I get a strange $asset->root() with webroot path and assets path concatenated

with relative url like in the suggested post I get the correct path of new new image, but not the reiszed thumb of the media folder

any suggestions very welcome, thanks

Why do you want to create an asset from that file? since it lives in the content folder, it is a normal image and can be treated like any other file.

Asset is useful for dealing with images outside the content folder.

thanks for you reply, How can I access the file object of an image in a subfolder of a pages folder, or is this bad practices and conflicts with possible subpages?

I’m Migrating to kirby3. In kirby2 I generated the watermarked image in the thumbs folder, since I could easily guess the path, but nor the paths are hashed in the meida folder, so I try to go a diffrent way

Not quite sure I understand your question. Of course you can access images in a subfolder from the current page. You can even access all images of all pages if you want or need to.

how can I loop through the images in /content/mypage/folder-contains-only-watermarked-jpgs/ and get their file objects in a template or plugin to be able to apply the resize method?

Depends on from where you are accessing them.

$images = page('mypage/folder-contains-only-watermarked-jpgs')->images();
foreach ($images as $image) {
  echo $image->resize(100);

From the parent page:

$images = $page->children()->find('folderwithimages')->images();

(not without checking if the page exists…)

great this works, didnt know the children() method is this universal, I was thiking it expects pages