-
- 89 Posts
Is there a way to resize an original uploaded image on upload/resource save by a plugin?
For example someone uploads an image 1920x and I always want images bigger then 1024x to be 1024x or smaller.
In my particular case I use the "Simple File Upload TV".
Any help/pointers are well appreciated!
Thanx in advance!
There is this, you might be able to convert it into a plugin. I'm not sure if uploading an image with that TV will trigger the OnFileManagerUpload event, you might need to use the OnDocFormSave event, and get the image that was just uploaded in the TV value.
http://forums.modx.com/thread/78871/compressing-resizing-images-on-upload
http://rtfm.modx.com/revolution/2.x/developing-in-modx/basic-development/plugins/system-events/onfilemanagerupload
Here's a plugin, unfortunately I don't read Russian...but the code is good
https://bezumkin.ru/sections/components/118/
I was afraid of that. Those file upload features don't trigger the file upload event. That complicates matters.
No, at least not on upload.
You can use pthumb/phpthumbof/whatever as an Output Modifier on your links to images, which will resize them on-the-fly while the page is being generated, so the image link actually points to the resized version. This gets cached, so the next time the image is requested it will take it from the cache rather than resize it again. But I think you already know that.
The only thing I can think of is a plugin using OnDocFormSave, to check for any images in TVs, get those images and resize them, replacing the uploaded image with the resized version. I wouldn't call that a trivial exercise, although it shouldn't be too difficult.
What we need is for file uploads using Media Sources to trigger the OnFileManagerUpload event.
-
- 89 Posts
Thanx for your reply.
I know how to copy paste and make little changes to code.
But that would go beyond my capacities.
It's a little beyond me right now as well. I already have a few things on my plate, as well as other more personal worries reducing my time and energy at the moment. I'll keep it in mind though, and maybe somebody else will be motivated to look into doing something about it.
I can see it not being a core function, but I can see having more actions triggering the system events, like uploading via a Media Source. After all, it does use the same browser and upload features that the File Manager does.