Selectively prevent generation of images in media folder

I would like to stop certain images from being processed by Kirby and being copied to the media folder. I have a site that uses Krpano which allows zooming in on very very high resolution images, by using sets of tiles at different resolutions. These have been manually placed into the content folders, and are 300mb each.

Theres about 20 of them so, in the interests of saving space, I want to stop Kirby moving them to the media folder. This will save a few gigabytes, and make the site perform faster, since Kirby is not needlessly processing these images.

Is that possible? They are in a subfolder called “Tiles”, under each page. So bascially if the pages content folder is called “Tiles”, I want Kirby to ignore any images underneath that, recursively.

Use this little plugin but on a condition:

Thanks, looks promising but i cant seem to get the condition to kick in. I tried this:

<?php

Kirby::plugin('hashandsalt/mediaskip', [
  'components' => [
    'file::url' => function (Kirby $kirby, $file) {
        if (strpos($file->parent()->diruri(), 'tiles') !== false) {
          return $kirby->url() . '/content/' . $file->parent()->diruri() . '/' . $file->filename();
        }
    },
  ]
]);

I think i need to use parents() but i think thats going to give me an array back, not a string?

How do i check for a folder called tiles somewhere in the files ancestry?

The folder structure looks like this:

Yes, you can either check if the $page->root() contains the string tiles, or in_array('tiles', $page->parents()).

Replace $page with $file->parent(), of course.

Hrmm… switched it to this but it doesn’t work either…

<?php

Kirby::plugin('hashandsalt/kirby-media-skip', [
  'components' => [
    'file::url' => function (Kirby $kirby, $file) {
        if (in_array('tiles', $file->parents())) {
          return $kirby->url() . '/content/' . $file->parent()->diruri() . '/' . $file->filename();
        }
    },
  ]
]);

Nor does this…

<?php

Kirby::plugin('hashandsalt/kirby-media-skip', [
  'components' => [
    'file::url' => function (Kirby $kirby, $file) {
        $path = $file->root();
        if (strpos($path, 'tiles') !== false) {
          return $kirby->url() . '/content/' . $file->parent()->diruri() . '/' . $file->filename();
        }
    },
  ]
]);

Should be if (in_array('tiles', $file->parent()->parents())) {

Nope, not it either… still seeing fresh tiles appearing in the media folder.

Are you modifying these images (resizing, cropping)? Because then it doesn’t work and you’d have to modify the fileversion url instead.

Nope, not at all. It happens when I browse the page and zoom in, then i see the tiles being created in the media folder. I’m not directly accessing those images in templates or snippets or anywhere at all, nor where they uploaded via the panel

Theres a “viewer” plugin from krpano in the template that loads them in from an XML file. It injects a canvas element onto the page via javascript and loads the images into that. When pano accesses the images, kirby moves them to the media folder.

It’s odd :slight_smile:

Have you tried without the condition, so that all images are served from the content folder (or at least those that are not resized/cropped)

It doesnt work without the condition either.

Strange, because it does for me, at least if I don’t modify the images. Have you made sure to empty the media folder, clear the cache etc.?

I didn’t clear the entire media folder, just the folder for the page in question. The images inside are 1:1 copies of the original.

Perhaps its ignoring the plugin. How can see which plugins Kirby is using (as in ones its succesfully recoginsing)?

If i pull up the browser inspector and look at the images on the page, its says they are coming from http://website.test/macros/some-project/tiles/l6/08/l6_08_13.jpg. If i hit that file directly in the browser, it redirects me to the copy in the media folder:

http://website.test/media/pages/macros/some-project/tiles/l6/08/2737481616-1557997906/l6_08_13.jpg

Still trying to get to the bottom of why this does not work. Is there anything else i can try?

I don’t think Kirby allows you to access files directly in the content folder (see the .htaccess).

If you don’t manage the images in the panel, you could move the tiles folder outside the content folder. Access images there directly if that is a public folder or define a route to it.

The .htaccess directive only blocks access to .txt/md/mdown files, you can access files in the content folder (unless you put the content folder outside the web root)

Yes, you are right.

@jimbobrjames the url to the images should contain /content/ otherwise you go via the media routes. The fileurl component can be overwritten by every plugin that was loaded after yours (alphabetic order). There seems to be a conflict with that, so no valid solution.

How does the image url endup in the xml file?

The xml looks like this. Just relative paths with wildcards that the javascript powering the viewer understands.

<level tiledimagewidth="41984" tiledimageheight="47982">
	<cylinder url="tiles/l8/%0v/l8_%0v_%0h.jpg" />
</level>
<level tiledimagewidth="20992" tiledimageheight="23992">
	<cylinder url="tiles/l7/%0v/l7_%0v_%0h.jpg" />
</level>
<level tiledimagewidth="10496" tiledimageheight="11996">
	<cylinder url="tiles/l6/%0v/l6_%0v_%0h.jpg" />
</level>
<level tiledimagewidth="5248" tiledimageheight="5998">
	<cylinder url="tiles/l5/%0v/l5_%0v_%0h.jpg" />
</level>
<level tiledimagewidth="2624" tiledimageheight="3000">
	<cylinder url="tiles/l4/%0v/l4_%0v_%0h.jpg" />
</level>
<level tiledimagewidth="1280" tiledimageheight="1462">
	<cylinder url="tiles/l3/%0v/l3_%0v_%0h.jpg" />
</level>
<level tiledimagewidth="640" tiledimageheight="732">
	<cylinder url="tiles/l2/%0v/l2_%0v_%0h.jpg" />
</level>
<level tiledimagewidth="256" tiledimageheight="292">
	<cylinder url="tiles/l1/%0v/l1_%0v_%0h.jpg" />
</level>

I’d say you should have there the direct path to the file in the contents folder /content/macro/…/xx.jpg

A custom route to match “tiles“ and redirect to or return the content/…image could be a more dynamic solution.

The full path doesnt work. Ive also just noticed that the xml file also gets moved to the media folder.

Additionally, the above plugin breaks the panel:

in_array() expects parameter 2 to be array, object given