Sinmok Posted May 16, 2013 Share Posted May 16, 2013 Guys, I'm looking to improve the inline editor to better support image editing but I've hit a roadblock. Assuming I know the field name of the pages' Pageimages object, how do you perform actions on that Pagearray and save it? Assuming you have a $files array, returned by Wireupload::Execute, how do you Replace the first image (single image) on that Pageimages array Delete X image from that array Reorder images in that array At the moment, my only working code so far is to do <?php $page->pageimages->deleteAll(); $page->pageimages->add($files[0]); $page->save(); Ideally, I'd like to keep the old files and just replace the first image with the newly uploaded file, but I can't figure out how you do that! And finally, how do you get information about an uploaded file before running execute? I need to know the uploaded images width and height before proceeding with the save, but I can't see any methods that might return that information. Any pointers? Link to comment Share on other sites More sharing options...
kongondo Posted May 16, 2013 Share Posted May 16, 2013 Btw, Have you seen this new Hooks page? Would probably be useful to you.. 1 Link to comment Share on other sites More sharing options...
horst Posted May 16, 2013 Share Posted May 16, 2013 Hi <eagle eye>kongondo</eagle eye>, this would probably be useful to me too. Link to comment Share on other sites More sharing options...
ryan Posted May 17, 2013 Share Posted May 17, 2013 I'm not sure that I understand the full context of what you are trying to do, but one thing that may be helpful is to consider that a Pageimages array is an extension of a WireArray and shares all the same methods and capabilities. ProcessWire 2.3 also has some new functions like insertBefore(), insertAfter() and replace(), that you may find handy here (though they aren't yet in the documentation page, I need to update it). And finally, how do you get information about an uploaded file before running execute? I'm not exactly sure what you mean about "execute", but you would need an image file to be present on the server before you could determine what the dimensions are. If you have an image that is just a filename, and not yet a Pageimage, then you could use the traditional PHP method of determining width/height, and that would be to use the PHP getimagesize() function. Link to comment Share on other sites More sharing options...
Sinmok Posted May 17, 2013 Author Share Posted May 17, 2013 I'm not sure that I understand the full context of what you are trying to do, but one thing that may be helpful is to consider that a Pageimages array is an extension of a WireArray and shares all the same methods and capabilities. ProcessWire 2.3 also has some new functions like insertBefore(), insertAfter() and replace(), that you may find handy here (though they aren't yet in the documentation page, I need to update it). I'm not exactly sure what you mean about "execute", but you would need an image file to be present on the server before you could determine what the dimensions are. If you have an image that is just a filename, and not yet a Pageimage, then you could use the traditional PHP method of determining width/height, and that would be to use the PHP getimagesize() function. Yeah, phrasing questions are not my strong point, but the replace() method you've told me about looks like it is exactly what I was looking for. Basically, for the image issue, I need to determine if the image that has been sent in the request complies with the 'max dimensions' specified in the fields properties, and reject the upload if it doesn't. I pass the sent file reference to WireUpload(), but I can't see any methods for retrieving image dimensions of the uploaded from the WireUpload object, so that I can compare it against the max dimensions properties of the image field. Hope that makes sense! Link to comment Share on other sites More sharing options...
Soma Posted May 17, 2013 Share Posted May 17, 2013 You may want to look at my ImagesManager. https://github.com/somatonic/ImagesManager/blob/master/ImagesManager.module#L509 Thing is if you upload image and attach it to page with $page->image->add(path.jpg) the max dimension won't be executed since it's not a PageImage object. I worked around that by creating the PageImage first and adding that. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now