Auto-resize every uploading images

Auto-resize every uploading images

by Piotr Adamcio -
Number of replies: 14

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?

Average of ratings: Useful (1)
In reply to Piotr Adamcio

Re: Auto-resize every uploading images

by John Provasnik -
Picture of Particularly helpful Moodlers Picture of Testers

Consider the image optimizer plugin? https://moodle.org/plugins/filter_imageopt

Average of ratings: Useful (1)
In reply to John Provasnik

Odp: Re: Auto-resize every uploading images

by Piotr Adamcio -
i know this plugin but it doesnt work ( i installed , configured and try using - its still in my moodle ). From computer when i add a picture 4,6 MB it sends end a get an information that the file is to big ( max 2 MB) . So it doesnt work as i expected.
Is there another way?
In reply to Piotr Adamcio

Re: Odp: Re: Auto-resize every uploading images

by Yevgenii Losonogov -

Unfortunately, there is no ready-made solution at the moment for moodle (:


In reply to Piotr Adamcio

Re: Auto-resize every uploading images

by Daniel Thies -
Picture of Core developers Picture of Plugin developers Picture of Testers

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.

In reply to Daniel Thies

Re: Auto-resize every uploading images

by Yevgenii Losonogov -
In the Moodle version 3.8, I did not find these settings.
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
In reply to Yevgenii Losonogov

Re: Auto-resize every uploading images

by Daniel Thies -
Picture of Core developers Picture of Plugin developers Picture of Testers
Yes the final pdf is slightly larger than the original which wraps the annotations around the image. However the editor displays a png image that is optimized for display in a browser. This image can be downloaded by right clicking the image in the editor and selecting view background image.
Average of ratings: Useful (1)
In reply to Daniel Thies

Re: Auto-resize every uploading images

by Yevgenii Losonogov -
It is best to find a solution for implementing imagemagick to optimize the image.
In reply to Yevgenii Losonogov

Odp: Re: Auto-resize every uploading images

by Piotr Adamcio -

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

In reply to Piotr Adamcio

Re: Odp: Re: Auto-resize every uploading images

by Daniel Thies -
Picture of Core developers Picture of Plugin developers Picture of Testers

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.

In reply to Daniel Thies

Re: Auto-resize every uploading images

by Yevgenii Losonogov -

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.








Average of ratings: Useful (2)
In reply to Yevgenii Losonogov

Re: Auto-resize every uploading images

by Daniel Thies -
Picture of Core developers Picture of Plugin developers Picture of Testers

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.

In reply to Daniel Thies

Re: Auto-resize every uploading images

by Yevgenii Losonogov -
Hi Daniel,

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.
In reply to Piotr Adamcio

Re: Auto-resize every uploading images

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
This issue of "filesizes" is present in almost anything that gets uploaded, not just photos. For example, if you want a student to upload a pdf file, the student's pdf file might be 10MB in size, whereas if one were to compress it, it would be only 15KB. A dramatic difference. Same thing for videos, audio, even PowerPoints and Word files.

I do like Daniels's suggestion to have a built-in link to some kind of File Converter.  This is an interesting approach.

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.)
Average of ratings: Useful (2)