# Thumb() of image outside of content folder not really working

**URL:** <https://forum.getkirby.com/t/thumb-of-image-outside-of-content-folder-not-really-working/5367>\
**Category:** Questions\
**Tags:** v2\
**Created:** [September 30, 2016, 4:14pm UTC](https://forum.getkirby.com/t/thumb-of-image-outside-of-content-folder-not-really-working/5367 "2016-09-30T16:14:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rasteiner](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rasteiner/32/4788_2.png) [@rasteiner](https://forum.getkirby.com/u/rasteiner)\
**Post date:** [September 30, 2016, 4:14pm UTC](https://forum.getkirby.com/t/thumb-of-image-outside-of-content-folder-not-really-working/5367/1 "2016-09-30T16:14:13Z")

</div>

the [docs](https://getkirby.com/docs/templates/thumbnails) suggest the following snippet for creating thumbnails of images outside of the content folder:

```
$myimage = new Media(
  // the absolute path for the file
  '/var/www/myimages/image.jpg',         
  // the absolute url
  'http://mydomain.com/images/image.jpg' 
);

echo thumb($myimage, array('width' => 300));

```

However this is misleading as it doesn’t work as expected.  
It seems like using the “thumb()” function like this makes it ignore any configuration you have in your config.php file (like the driver to use…). And for some reason it defaults to the “im” driver (so on systems without imagemagick you get a “sh: 1: convert: not found” error).

I’ve made a quick example with starterkit here: [GitHub - rasteiner/kirbythumbs: kirby thumb not working as expected](https://github.com/rasteiner/kirbythumbs) so people can verify it.  
Look at the home template.

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [September 30, 2016, 6:01pm UTC](https://forum.getkirby.com/t/thumb-of-image-outside-of-content-folder-not-really-working/5367/2 "2016-09-30T18:01:38Z")

</div>

Since Kirby 2.3 this is intended behavior for the `Media` class (it is part of the Toolkit and we made the thumb generation independent from the Kirby CMS so that it can be used in other projects).

What you are looking for is the new `Asset` class:

```auto
$myimage = new Asset($filepath);

echo thumb($myimage, array('width' => 300));

```

`$filepath` should be a relative path like `assets/images/myimage.jpg`.

* * *

It looks like we forgot to update the docs, I will do so now. Thanks for letting us know.

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [August 22, 2017, 8:17am UTC](https://forum.getkirby.com/t/thumb-of-image-outside-of-content-folder-not-really-working/5367/3 "2017-08-22T08:17:25Z")

</div>

Does this really work? I’m redesigning an old site right now and it does not work.

**I do this:**

```php
$image_path = 'D:\projects\sites\vardagsfinans.se\assets\images\avatars\128-15.jpg';
$image_object = new Asset($image_path);
echo thumb($image_object, array('width' => 100));

```

It displays nothing and shows no errors. When I use `var_dump` on the `$image_object` I get this:

```nohighlight
Asset Object
(
    [root] => 
    [url] => http://localhost/sites/vardagsfinans.se/D:\projects\sites\vardagsfinans.se\assets\images\avatars\128-15.jpg
    [hash] => d41d8cd98f00b204e9800998ecf8427e
    [dir] => 
    [filename] => 128-15.jpg
    [name] => 128-15
    [safeName] => 128-15.jpg
    [extension] => jpg
    [size] => 
    [niceSize] => 0 kB
    [modified] => 
    [mime] => 
    [type] => 
    [dimensions] => Dimensions Object
        (
            [width] => 0
            [height] => 0
            [ratio] => 0
            [orientation] => 
        )

    [isWritable] => 
    [isReadable] => 
    [isExecutable] => 
    [header] => Content-type: 
    [exif] => Exif Object
        (
            [camera] => 
            [location] => 
            [timestamp] => 
            [exposure] => 
            [aperture] => 
            [iso] => 
            [focalLength] => 
            [isColor] => 
        )

)

```

The url is messed up as it contains both the url and the path on the same row. The dimensions are set to 0 so I guess it does not read the image file correctly.

I use Kirby 2.5.4.

---

<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:** [August 22, 2017, 9:19am UTC](https://forum.getkirby.com/t/thumb-of-image-outside-of-content-folder-not-really-working/5367/4 "2017-08-22T09:19:26Z")

</div>

> [@jenstornell](#):
>
> $image\_path = ‘D:\projects\sites\vardagsfinans.se\assets\images\avatars\128-15.jpg’;  
> $image\_object = new Asset($image\_path);  
> echo thumb($image\_object, array(‘width’ =\> 100))

You path is not correct:

```auto
$image_path = 'assets/images/image.jpg';
$image_object = new Asset($image_path);
dump($image_object);
echo thumb($image_object, array('width' => 100));

```

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [August 22, 2017, 11:20am UTC](https://forum.getkirby.com/t/thumb-of-image-outside-of-content-folder-not-really-working/5367/5 "2017-08-22T11:20:11Z")

</div>

It works, thanks! 🙂

So the assets class does not support an absolut path as a param.

**I get many paths and foreach them with `glob`, which mean I need to modify the paths afterwards:**

```php
// $image_path is generated with glob
$image_path = ‘D:\domain.com\assets\images\image.jpg’;
$image_object = new Asset(str_replace(kirby()->roots()->index(), '', $image_path));
echo thumb($image_object, array('width' => 100));

```

I feel it’s a bit hacky. Is there a better way to solve it? Maybe add an issue to make it support absolute paths?

---

<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:** [August 22, 2017, 11:35am UTC](https://forum.getkirby.com/t/thumb-of-image-outside-of-content-folder-not-really-working/5367/6 "2017-08-22T11:35:41Z")

</div>

You can pass an absolute URL (like, one starting with http(s)://, but not an absolute file path, it seems:

```auto
<?php

abstract class AssetAbstract extends Media {
  
  public $kirby = null;  

  use Kirby\Traits\Image;

  public function __construct($path) {
    $this->kirby = kirby::instance();
    if(is_a($path, 'Media')) {
      parent::__construct($path->root(), $path->url());
    } else {
      parent::__construct(
        url::isAbsolute($path) ? null : $this->kirby->roots()->index() . DS . ltrim($path, DS), 
        url::makeAbsolute($path)
      );
    }
  }

}

```

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [August 22, 2017, 12:15pm UTC](https://forum.getkirby.com/t/thumb-of-image-outside-of-content-folder-not-really-working/5367/7 "2017-08-22T12:15:23Z")

</div>

Ahh, I see. It does not help me with this issue but good to know how it’s ment to be used.

**I added an issue about it:** [https://github.com/getkirby/kirby/issues/599](https://github.com/getkirby/kirby/issues/599)

Thanks!

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:32pm UTC](https://forum.getkirby.com/t/thumb-of-image-outside-of-content-folder-not-really-working/5367/8 "2025-02-06T17:32:16Z")

</div>

Archived on February 6, 2025, 5:32pm UTC


