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
I would do it with a model observer.
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?
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
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
well, you have the name of the file, grab it with the Storage facade and do what you need to with it.
Oh I see. I'll give that a shot. Thanks!