diff --git a/classes/CompressJob.php b/classes/CompressJob.php index 2c7e4a2..a406b85 100644 --- a/classes/CompressJob.php +++ b/classes/CompressJob.php @@ -18,13 +18,18 @@ class CompressJob { public function fire($job, $data) { $this->attachment_id = $data['attachment_id']; + $this->attachment = Attachment::find($this->attachment_id); + + if (!$this->shouldResize()) { + return; + } + $this->crop = $data['crop']; $this->sizes = Setting::get('srcx'); Storage::disk($this->disk)->makeDirectory('cropped'); - $this->attachment = Attachment::find($this->attachment_id); $this->fullPath = Storage::disk($this->disk)->path($this->attachment->source->path); $this->crop(); @@ -73,4 +78,8 @@ class CompressJob { return app($this->strategy); } + private function shouldResize() { + return $this->attachment->source->isCroppable(); + } + } diff --git a/models/SourceFile.php b/models/SourceFile.php index 7d40eda..4660791 100644 --- a/models/SourceFile.php +++ b/models/SourceFile.php @@ -12,6 +12,8 @@ class SourceFile extends Model protected $slugs = ['slug' => 'basename']; + protected $croppableTypes = [ 'image/jpeg', 'image/gif', 'image/png', 'image/webp' ]; + /** * @var string The database table used by the model. */ @@ -59,4 +61,8 @@ class SourceFile extends Model public function getSizeAttribute() { return Storage::disk('uploads')->size($this->path); } + + public function isCroppable(): bool { + return in_array($this->type, $this->croppableTypes); + } }