I am trying to write a function that will resize uploaded images to a max of 2000 x 2000, and overwrite the image file, but the documentation is minimal and confusing. My hope is to run this from a Controller function, but i can only seem to find the documentation for template manipulations SS4 Docs on Images
I can find all of the classes involved with image manipulation, but can’t seem to find any working examples of this code to guide me.
That actually looks perfect for your needs @EEKim. You could just copy the ResampleImage extension and update that for SS4. It’s much simpler code than I would have expected, maybe because it bypasses SilverStripe APIs to produce a resampled image and replace the original.
Yeah probably, i was hoping that there was some way to use the native SS functions rather than having to write my own, i just can’t seem to figure out how the manipulated files are saved. I guess i will have to keep digging in the “Resampled” code.
Thanks for the suggestion though, i may have to use it in the end
@JonoM Actually that’s the plugin I was trying to base this code on, ideally outside an extension for this particular thought, but I may have to give up on it.
I am running into errors with “getFullPath()”, unlink() doesn’t work in SS4 from anything i’ve been able to test, and “WriteTo” is failing when i manage to get the ‘cloned’ version to return based on the tutorial i posted. ( i got rid of a lot of my test code so i don’t have error messages to paste in at the moment )
I will keep trying today, see if i can use the GD Class directly, but i am still having problems getting it to overwrite
EDIT:: the big issue that i am having is that i am trying to find an equivalent of the “getFullPath()” function, as this doesn’t exist on images anymore, and I am having real trouble finding it’s equivalent
Mmm yeah flysystem is probably going to make that hard to access. I guess as a last resort you could reverse engineer a filesystem path from the relative URL.
Yeah apparently, I was wishing that there was some way to use the native SS functions preferably than having to write my personal, I just can’t look to figure out how the managed files are stored. I suppose I will have to avert digging in the “Resampled” code