Hi i wonder is it possible to autoresize uploaded images files in course in "add an activity or resource" like workshop or assignment which allow teacher to add task or collect homework . Students (primary school) trying to send their homework
but when they make a picture using their phone the picture has usually 3 -5 MB or more. Even if they use computer they try to add images and they are usually to big. They have problem with using another external tool so thats is my question. there is any suggestion or possibilities how to change size while loading file?
Consider the image optimizer plugin? https://moodle.org/plugins/filter_imageopt
Is there another way?
Unfortunately, there is no ready-made solution at the moment for moodle (:
Actually there is a standard feature that does this although it could be fine tuned. The pdf feedpack plugin for assign does generated a compressed or reduced resolution image that is substantially smaller than the original.
To do see this set up assignment where students upload a full scale image and enable pdf feedback under the feedback options in the setting. The image converter needs to be set by the admin and ghostscript installed for it to work correctly. When the teacher grades the assignment an image is generated for the teacher to see and to mark with annotations. The image is reduced from the original resolution. You can right click the image and select 'View background image' to download the png image. I uploaded a 4M jpeg image file and downloaded a 825K png file. The ghostscript options in edit pdf plugin could be changed to give a better result.
Unfortunately, the file converter is difficult for most admins to set up or they do not do it for various reasons, but it actually performs some very useful functions.
assignfeedback_editpdf (2019111800).
There are only settings:
- assignfeedback_editpdf | default
- assignfeedback_editpdf | stamps
I uploaded a 4M jpeg image file and downloaded 4.1M pdf file
Is it possible that every uploaded file can be placed in temp (unlimited or limited upload due to php.ini setings upload_max_filesize = ,
post_max_size = , ) and then imagemagic could convert it to max "Maximum upload size" from the course settings or even everyone who wants upload could have settings where he can resize image, change size, (some things from imagemagic converter) or may student have checkbox to see this file before accepting and finishing the upload or if they dont want only finish upload. After changes file should finish upload and placing in right place in the course. https://www.php.net/manual/en/book.imagick.php
The upload a file function is a repository plugins. Instead of using 'Upload file' users have the option to selct files from 'Server files' and 'Private files' repositories in activities. So in principle a file could be uploaded to Moodle and compressed. The compressed file could be loaded from one of those repositories. A new repository plugin might also be made that would of compressed versions the users Private files.
Actually I think there must already be (or one time were) ways of doing the with existing repository plugins (Flickr, Picasso, Gdocs etc.). For example users can upload a file to G Drive, manipulate it with Docs tools, and then use plugin integration to insert the content in any activity. That requires admin to set up the integration and for users to set up account with the service and then link them with Moodle. This should also work with the other office suite integration.
Currently, I have managed to create a separate plugin for uploading the response as a photo. This plugin now works identically to the answer plugin as a file. The only thing I can’t do now is to process uploaded photo files through ImageMagick processing.
To do this, I need more time to work out the necessary algorithm when implementing an additional function using ImageMagick for processing graphic images, unloading organized in my new plugin for moodle.
Hi Yevgenii,
That looks like a really cool idea for a plugin. Imagemagick is a more capable than gd is usually used in core.
I discovered another way to handle this is with the database activity. You can add a picture field in a template with image dimensions specified for single and list view. The templates are displayed with thumbnails generated to the specified values. Clicking views original, but thumbnails can be downloaded with right click. Sometimes the conversion fails silently (depending on dimensions) and the original image is resized in browser.
Initially, I was thinking of adding an additional basic settings option to the new plugin:
width (px) x height (px) and image compression quality.
This can be done in the form of a drop-down list or enter values in the form field manually.
Now this task is not the main thing for me.
Currently, I see 3 ways to solve this task.
1) At the moment, my main task is to find the optimal solution for inserting the image processing function through ImageMagick, which works only through the file entry and exit procedure.
Otherwise, you can restart the server’s central processor, which may slow down the kernel moodle.
In order not to overload the server’s CPU during mass processing of photo files, which may lead to a slowdown in the moodle core performance.
I don’t want to make changes to the moodle kernel code either. Otherwise, every time after updating the kernel of the system, me will have to make additional code changes every time.
2) At the time of the formation of the pdf document when creating a temporary png file from the original downloaded photo file - at this moment can add the ImageMagick function to optimize the photo according to the parameters set in advance.
In the work of this procedure there will be no mass load on the central processor of the server until the teacher opens the desired original file through the "grade" tool.
3) The next version of the tool is related to photo optimization. Need to create a new script separate from moodlethat will work only in a specific moodeldata directory and process the newly created graphics extension files in it.
Now the main thing is to decide on the right decision on choosing the optimal path.
A lot of the work may all ready have been done in Moodle with editpdf with the File converters api https://docs.moodle.org/dev/File_Converters . You could create and file converter plugin with Imagemagick that would create thumbnails.
It may be a little difficult to expect Moodle to have build-in filesize optimizers for all of these various formats. Maybe someday. But until that day, the best thing that I have found is to try to explain to students how to reduce the size of media. For example, in my "Introduce Yourself" forum, I tell students that they can upload pictures, but to try to keep their pictures to 400x400 pixels. Do they listen?
(Ans: No. I have yet to show them the easiest universal way to do this.)