Add isCroppable and abort resizer when image is not croppable
This commit is contained in:
parent
a345db162a
commit
efe0b265a6
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue