Add isCroppable and abort resizer when image is not croppable

This commit is contained in:
philipp lang 2020-10-29 21:56:35 +01:00
parent a345db162a
commit efe0b265a6
2 changed files with 16 additions and 1 deletions

View File

@ -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();
}
}

View File

@ -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);
}
}