get($this->filename); // Open file $image = Image::fromStorage($this->filename, 'local'); try { $width = $image->width(); } catch (ImageException) { // not an image; delete file and end job Storage::disk('local')->delete($this->filename); return; } // Save the file publicly Storage::disk('public')->put($this->filename, $file); // Create smaller versions if necessary if ($width > 1000) { $filenameParts = explode('.', $this->filename); $extension = array_pop($filenameParts); // the following achieves this data flow // foo.bar.png => ['foo', 'bar', 'png'] => ['foo', 'bar'] => foo.bar $basename = trim(implode('.', $filenameParts), '.'); Storage::disk('public')->put($basename.'-medium.'.$extension, $image->scale(width: 1000)->toBytes()); Storage::disk('public')->put($basename.'-small.'.$extension, $image->scale(width: 500)->toBytes()); } // Now we can delete the locally saved image Storage::disk('local')->delete($this->filename); } }