# Selectively prevent generation of images in media folder

**URL:** <https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533>\
**Category:** Questions\
**Tags:** v3\
**Created:** [June 10, 2019, 10:43am UTC](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533 "2019-06-10T10:43:22Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [June 10, 2019, 10:43am UTC](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533/1 "2019-06-10T10:43:22Z")

</div>

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](https://krpano.com) 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.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 10, 2019, 12:08pm UTC](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533/2 "2019-06-10T12:08:08Z")

</div>

Use this little plugin but on a condition:

> [@Image URLs - How to remove string?](https://forum.getkirby.com/t/image-urls-how-to-remove-string/13153/10):
>
> Hey everyone, there are a bunch of reasons, why we went for this solution based on feedback from many users during v2. In v2, direct URLs to files always included the sorting number of folders. Whenever you changed the sorting of a page the URL to all its files would break. This is less than ideal for SEO and consistent URLs in general. With the new media API you always get the same URL no matter how the pages are sorted. URLs to files only change when the file itself is being modified. In v2…

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [June 10, 2019, 12:32pm UTC](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533/3 "2019-06-10T12:32:44Z")

</div>

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

```auto
<?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:

 ![tiles](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/7/7abf44c47d4e2ab657f1f6c9c0cf255a2fabffc7.jpeg)

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 10, 2019, 12:45pm UTC](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533/4 "2019-06-10T12:45:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [June 10, 2019, 12:51pm UTC](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533/5 "2019-06-10T12:51:22Z")

</div>

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

```auto
<?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…

```auto
<?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();
        }
    },
  ]
]);

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 10, 2019, 1:09pm UTC](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533/6 "2019-06-10T13:09:19Z")

</div>

> [@jimbobrjames](#):
>
> if (in\_array(‘tiles’, $file-\>parents())) {

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

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [June 10, 2019, 1:14pm UTC](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533/7 "2019-06-10T13:14:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 10, 2019, 1:24pm UTC](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533/8 "2019-06-10T13:24:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [June 10, 2019, 1:39pm UTC](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533/9 "2019-06-10T13:39:25Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 10, 2019, 1:56pm UTC](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533/10 "2019-06-10T13:56:29Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [June 10, 2019, 2:00pm UTC](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533/11 "2019-06-10T14:00:42Z")

</div>

It doesnt work without the condition either.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 10, 2019, 2:02pm UTC](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533/12 "2019-06-10T14:02:55Z")

</div>

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.?

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [June 10, 2019, 2:05pm UTC](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533/13 "2019-06-10T14:05:58Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [June 11, 2019, 10:08am UTC](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533/14 "2019-06-11T10:08:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![moeli](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/moeli/32/8964_2.png) [@moeli](https://forum.getkirby.com/u/moeli)\
**Post date:** [June 11, 2019, 11:17am UTC](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533/15 "2019-06-11T11:17:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 11, 2019, 11:23am UTC](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533/16 "2019-06-11T11:23:37Z")

</div>

> [@moeli](#):
>
> I don’t think Kirby allows you to access files directly in the content folder (see the .htaccess).

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)

---

<div class="post-metadata">

**Author:** ![moeli](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/moeli/32/8964_2.png) [@moeli](https://forum.getkirby.com/u/moeli)\
**Post date:** [June 11, 2019, 11:48am UTC](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533/17 "2019-06-11T11:48:04Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [June 11, 2019, 11:59am UTC](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533/18 "2019-06-11T11:59:26Z")

</div>

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

```auto
<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>

```

---

<div class="post-metadata">

**Author:** ![moeli](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/moeli/32/8964_2.png) [@moeli](https://forum.getkirby.com/u/moeli)\
**Post date:** [June 11, 2019, 12:02pm UTC](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533/19 "2019-06-11T12:02:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [June 11, 2019, 12:18pm UTC](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533/20 "2019-06-11T12:18:28Z")

</div>

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:

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

```

[Next page](https://forum.getkirby.com/t/selectively-prevent-generation-of-images-in-media-folder/14533.md?page=2)
