# How to create file object form assets folder?

**URL:** <https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180>\
**Category:** Questions\
**Tags:** v3\
**Created:** [January 16, 2019, 7:25pm UTC](https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180 "2019-01-16T19:25:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![simon.bed](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/simon.bed/32/6413_2.png) [@simon.bed](https://forum.getkirby.com/u/simon.bed)\
**Post date:** [January 16, 2019, 7:25pm UTC](https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180/1 "2019-01-16T19:25:10Z")

</div>

Hi everyone 🖐

In Kirby 2, I was able to create file object base on images from the assets folder.  
I was using this line :

`new Asset(“images/…../……jpg”)`

In **kirby 3** , this class is not working anymore.

I tried to use `File::create($props)` , but i’m not sure what to put in the $props array.  
[https://getkirby.com/docs/reference/file/create](https://getkirby.com/docs/reference/file/create)

Is someone know how to create file object from the assets 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:** [January 16, 2019, 7:39pm UTC](https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180/2 "2019-01-16T19:39:51Z")

</div>

You can use

```auto
$image = new Kirby\Image\image('assets/images/myimage.jpg);

```

You can’t call `resize()` or so on that object, though. We will have a replacement for the Assets class at a later date.

---

<div class="post-metadata">

**Author:** ![simon.bed](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/simon.bed/32/6413_2.png) [@simon.bed](https://forum.getkirby.com/u/simon.bed)\
**Post date:** [January 16, 2019, 8:39pm UTC](https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180/3 "2019-01-16T20:39:54Z")

</div>

> [@texnixe](#):
>
> $image = new Kirby\Image\image('assets/images/myimage.jpg);

Good, so I cannot create thumbnail like so:  
` $image = new Kirby\Image\image("assets/images/myimage.jpg");`  
`$image->thumb(['width'=> 320])->url();`

---

<div class="post-metadata">

**Author:** ![bvdputte](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bvdputte/32/8179_2.png) [@bvdputte](https://forum.getkirby.com/u/bvdputte)\
**Post date:** [January 17, 2019, 7:54am UTC](https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180/4 "2019-01-17T07:54:21Z")

</div>

I have encountered the same during the beta’s. I’m convinced the Kirby team will come up with something which makes this possible soon.

You can however already use the `Darkroom` factory to generate thumbnails, but in my experience you’ll have to redo a lot of the things Kirby otherwise does for you.

Let’s hope this lands soon in Kirby 🤞

---

<div class="post-metadata">

**Author:** ![bastianallgeier](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bastianallgeier/32/7569_2.png) [@bastianallgeier](https://forum.getkirby.com/u/bastianallgeier)\
**Post date:** [January 24, 2019, 12:16pm UTC](https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180/5 "2019-01-24T12:16:31Z")

</div>

Sorry for missing a better solution right now. I think we already have a ticket for it and will fix this in a future release.

---

<div class="post-metadata">

**Author:** ![bvdputte](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bvdputte/32/8179_2.png) [@bvdputte](https://forum.getkirby.com/u/bvdputte)\
**Post date:** [January 24, 2019, 4:13pm UTC](https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180/6 "2019-01-24T16:13:49Z")

</div>

That’ld be great, @bastianallgeier. Thx!

I’ld need something like that to deal with virtual pages that come with images attached.

---

<div class="post-metadata">

**Author:** ![Matthias](https://avatars.discourse-cdn.com/v4/letter/m/cdc98d/32.png) [@Matthias](https://forum.getkirby.com/u/Matthias)\
**Post date:** [January 28, 2019, 9:29pm UTC](https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180/7 "2019-01-28T21:29:24Z")

</div>

Yes, please re-introduce the Asset class! It‘s been quite useful.

---

<div class="post-metadata">

**Author:** ![daybugging](https://avatars.discourse-cdn.com/v4/letter/d/2acd7d/32.png) [@daybugging](https://forum.getkirby.com/u/daybugging)\
**Post date:** [February 4, 2019, 1:41am UTC](https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180/8 "2019-02-04T01:41:47Z")

</div>

So, where are we standing with this?

For the time being, I would glady define global images / etc in the settings page, but this isn’t editable either - so how would I go about just grabbing an image from the assets folder, resize and output it, say, in my header snippet?

thx!

---

<div class="post-metadata">

**Author:** ![GilDev](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/gildev/32/6158_2.png) [@GilDev](https://forum.getkirby.com/u/GilDev)\
**Post date:** [February 5, 2019, 11:21pm UTC](https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180/9 "2019-02-05T23:21:31Z")

</div>

Woaw, after searching for so long, I finally found an answer with this post: it’s currently not possible to get an Image object from the assets folder… =’)

The documentation is quite vague about assets in general, I haven’t even found the default path to the assets folder anywhere (it should at least be noted in the [`$kirby->url('assets')`](https://getkirby.com/docs/reference/system/urls/assets) documentation I think), I just know it from Kirby 2.  
I think it would be quite nice if we could do `$kirby->asset('images/myimage.png')` to get the corresponding File object, but then it would be necessary to have a method to get the Image object I guess.

Anyway, I hope this will soon be updated, thanks for the great work!

---

<div class="post-metadata">

**Author:** ![11bits](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/11bits/32/860_2.png) [@11bits](https://forum.getkirby.com/u/11bits)\
**Post date:** [February 9, 2019, 6:38pm UTC](https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180/10 "2019-02-09T18:38:18Z")

</div>

I’m replacing:

```auto
<?= (new Asset("assets/images/menu.svg"))->content() ?>

```

with

```auto
<?= new Kirby\Image\image("assets/images/menu.svg") ?>

```

but I only get the image URL. What am I doing wrong?

---

<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:** [February 9, 2019, 6:55pm UTC](https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180/11 "2019-02-09T18:55:20Z")

</div>

The new Asset class is available on the develop branch.

What do you expect to get? An image tag?

You have to use an image tag and put the image object as src attribute:

```auto
<img src="<?= url(new Kirby\Image\image("assets/images/menu.svg")) ?>">

```

---

<div class="post-metadata">

**Author:** ![11bits](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/11bits/32/860_2.png) [@11bits](https://forum.getkirby.com/u/11bits)\
**Post date:** [February 9, 2019, 7:14pm UTC](https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180/12 "2019-02-09T19:14:45Z")

</div>

That’s the way (I like it)

Thanks

---

<div class="post-metadata">

**Author:** ![11bits](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/11bits/32/860_2.png) [@11bits](https://forum.getkirby.com/u/11bits)\
**Post date:** [February 9, 2019, 7:23pm UTC](https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180/13 "2019-02-09T19:23:07Z")

</div>

Ah, but in that way I’m not getting the svg code, is the same as if I use:

```auto
<img src="assets/images/menu.svg">
```

---

<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:** [February 9, 2019, 7:25pm UTC](https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180/14 "2019-02-09T19:25:30Z")

</div>

That’s why I asked what you expected. `svg()` helper to the rescue:

```auto
<?php echo svg(new Kirby\Image\image("assets/images/menu.svg")) ?>

```

---

<div class="post-metadata">

**Author:** ![11bits](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/11bits/32/860_2.png) [@11bits](https://forum.getkirby.com/u/11bits)\
**Post date:** [February 9, 2019, 7:28pm UTC](https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180/15 "2019-02-09T19:28:36Z")

</div>

That’s definitely the way.

Thanks again

---

<div class="post-metadata">

**Author:** ![simon.bed](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/simon.bed/32/6413_2.png) [@simon.bed](https://forum.getkirby.com/u/simon.bed)\
**Post date:** [April 1, 2019, 5:49pm UTC](https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180/16 "2019-04-01T17:49:20Z")

</div>

Hi, 🖐

i’m still not sure what is the best solution to **resize** images from the assets folder.

I’m trying to create a srcset for my image.

Does someone has a working solution? 🙂

---

<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:** [April 1, 2019, 7:32pm UTC](https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180/17 "2019-04-01T19:32:38Z")

</div>

@simon.bed You can use the `Asset` class:

```auto
$asset = new Asset("assets/images/someimage.jpg");
echo $asset->resize(100);

```

---

<div class="post-metadata">

**Author:** ![max](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/max/32/129_2.png) [@max](https://forum.getkirby.com/u/max)\
**Post date:** [May 16, 2021, 6:40pm UTC](https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180/18 "2021-05-16T18:40:39Z")

</div>

@texnixe This solution has worked for me, but breaks when I try and combine it with the CDN setup described [in the cookbook](https://getkirby.com/docs/cookbook/extensions/kirby-loves-cdn). The new asset breaks the `file::version` component returning the following error:

```auto
Argument 2 passed to Kirby\Toolkit\F::{closure}() must be an instance of Kirby\Cms\File, instance of Kirby\Cms\Asset given, called in /Users/max/Sites/prism/kirby/src/Cms/FileModifications.php on line 194

```

Please let me know if you see an easy way around this. Thanks!

---

<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:** [May 16, 2021, 6:59pm UTC](https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180/19 "2021-05-16T18:59:49Z")

</div>

Quick guess, check if it works if your remove the type hint `File` from this line:

```auto
'file::version' => function (Kirby $kirby, File $file, array $options = []) {

```

---

<div class="post-metadata">

**Author:** ![max](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/max/32/129_2.png) [@max](https://forum.getkirby.com/u/max)\
**Post date:** [May 16, 2021, 8:07pm UTC](https://forum.getkirby.com/t/how-to-create-file-object-form-assets-folder/12180/20 "2021-05-16T20:07:48Z")

</div>

@texnixe thanks for the help. that fixes the error and allows the CDN link to be generated. However the image asset does not show up in the kirby /media folder. So the CDN can’t to pull it in. Any thoughts on how to handle that?

As a workaround, I’m making an assets folder within the content folder `content/assets` and hide it from the panel. This way I can access images with the standard Kirby tools and the CDN plugin should work as expected. Seems fine this way!
