]> BookStack Code Mirror - bookstack/blob - app/Uploads/Image.php
3657aa9469d2bac249fe0b146608a4784ba96eef
[bookstack] / app / Uploads / Image.php
1 <?php namespace BookStack\Uploads;
2
3 use BookStack\Entities\Models\Page;
4 use BookStack\Model;
5 use BookStack\Traits\HasCreatorAndUpdater;
6
7 /**
8  * @property int $id
9  * @property string $name
10  * @property string $url
11  * @property string $path
12  * @property string $type
13  * @property int $uploaded_to
14  * @property int $created_by
15  * @property int $updated_by
16  */
17 class Image extends Model
18 {
19     use HasCreatorAndUpdater;
20
21     protected $fillable = ['name'];
22     protected $hidden = [];
23
24     /**
25      * Get a thumbnail for this image.
26      * @throws \Exception
27      */
28     public function getThumb(int $width, int $height, bool $keepRatio = false): string
29     {
30         return app()->make(ImageService::class)->getThumbnail($this, $width, $height, $keepRatio);
31     }
32
33     /**
34      * Get the page this image has been uploaded to.
35      * Only applicable to gallery or drawio image types.
36      */
37     public function getPage(): ?Page
38     {
39         return $this->belongsTo(Page::class, 'uploaded_to')->first();
40     }
41 }