Image Processing

Is it possible to programmatically access uploaded images for processing? Ideally I'd like to run Spatie's image optimizer on any images uploaded before they are saved through the FileUpload field type and the files uploaded in the RichEditor field type. I realize I can run it against files already uploaded to the disks, but it would be nice to process the images before they are saved to disk.
6 Replies
awcodes
awcodes2y ago
I would do it with a model observer.
bennett
bennettOP2y ago
I'd considered that, but I assume I need access to the file at it's temporary storage location before it's saved to my S3 bucket. With an observer I'd only have access to the underlying model properties.. right?
awcodes
awcodes2y ago
you should have access to the temporary file, which you can use to process. pretty sure the file object is available creating and updating should have access to the form data
bennett
bennettOP2y ago
This is the form data the Creating and Created observer for my Article model is picking up. 'cover_photo_url' is just an appends value. Created and Creating seem to be the same, less the ID and Timestamps
awcodes
awcodes2y ago
well, you have the name of the file, grab it with the Storage facade and do what you need to with it.
bennett
bennettOP2y ago
Oh I see. I'll give that a shot. Thanks!

Did you find this page helpful?