Help!: Alpha version of Grid format for Moodle 2.4

Help!: Alpha version of Grid format for Moodle 2.4

by Gareth J Barnard -
Number of replies: 15
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi,

I've created an 'alpha' version of the grid format for Moodle 2.4 available from:

https://github.com/gjb2048/moodle-courseformat_grid/archive/V2.4.0.1.zip

I've made it work and accept png files but for some unknown reason the images do not display.  In working though the code (editimage.php), they are uploaded to the user's draft area and converted successfully with an entry in the 'files' table and physically stored in the 'filedir' folder within the moodle data folder.  And changing the extension to the filename that matches the filename hash to the file type, i.e. '.png' gives the ability to preview the file and confirm it is ok.  Hacking '/lib/filelib.php' - 'readstring_accel' function and changing the mime type to text makes the browser display the returned bytes as text and this shows that indeed an image is being transferred.  Accessing the link directly (i.e. 'http://localhost/moodlegjb/pluginfile.php/15/course/section/2/Columns_Screen_Shot_24_edit.png') also fails with FireFox reporting that the image is corrupt.

I'm stumped and not sure if it is my set up or not.  I have cleared browser caches, operated a 2.3 version that works, compared changes in '/lib/filelib.php' and run a virtual linux machine with chrome and firefox browsers.

Any help appreciated.

Cheers,

Gareth

Average of ratings: -
In reply to Gareth J Barnard

Re: Help!: Alpha version of Grid format for Moodle 2.4

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

Gareth,

I dont think its your setup because I get the same thing - I haven't got as far or as deep as you with the testing but the same issues on my set up, both with a full Windows server and with a localhost test system on Linux.

Richard

Average of ratings: Useful (1)
In reply to Richard Oelmann

Re: Help!: Alpha version of Grid format for Moodle 2.4

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Dear Richard,

Thank you for testing.  I've recently done some more work but not solved the issue, current code on: https://github.com/gjb2048/moodle-courseformat_grid/tree/MOODLE_24_STABLE

I thought it might be the BOM issue but no, then that there was no format_grid class but no and that there was a conflict with lib.js but again no.

It is interesting to note with developer level debug and errors outputted on the screen that doing certain things cause error output but with no message.  Like editing on / off and submitting a new icon.  So, I'm working on the basis that something is throwing an exception that is not being explained.  Also looking in the Apache / PHP logs.  I'm considering installing PHPUnit to run the unit tests.

One approach might be to comment out most of renderer.php and get to a point where the odd error does not happen, then phase things back until the error occurs - time consuming.  Additionally, I'm going to double check use of new get_fast_modinfo() etc.

Cheers,

Gareth

In reply to Gareth J Barnard

Re: Help!: Alpha version of Grid format for Moodle 2.4

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Dear all,

This is the latest Alpha version: https://github.com/gjb2048/moodle-courseformat_grid/archive/V2.4.0.2.zip

I still cannot work out why the images are not showing.  I have (as an aid memior for myself too):

  • Worked through the entire image delivery mechanism to discover that the images are being stored and read back correctly in the Moodle meta data area.  What is read back in by the 'readfile()' core function is the same amount of bytes as on the disk.
  • If the image file is copied and manually tagged then it displays (with addition of the correct file extension).
  • I went through the entire set of files elminating each one to see if any caused the odd 'editing on / off' error above.
  • Refactored the JavaScript so it uses the Page Requirements Manager.
  • Used the same images in another non Grid format course to discover they display.
  • Incorporated the same images in labels, in the Grid format they do not display in another format they do.
  • Checked PHP error logs.
  • Looked at all the rendering code to see that it matches what it should be for 2.4.
  • And yet FireBug in FireFox reports that the images are corrupt!

I can only think of reimplementing the entire format from scratch by phasing in the old code bit by bit in brand new files and see when the error occurs - this will take a lot of time.

Any thoughts?

Cheers,

Gareth

In reply to Gareth J Barnard

Re: Help!: Alpha version of Grid format for Moodle 2.4

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Gareth - have you tried downloading the images and viewing them in a hex editor?

That will usually let you know if there are any extra error messages or whitespace that is corrupting the files.

You should also check that all the PHP files involved in the process have no ?> tags at the end of them (as any whitespace after those tags could be inserted into the download, leaving them out altogether allows PHP to close the file without any danger of unwated characters).

Finally, I would suggest using xdebug + compatible IDE (e.g. PHPStorm, netbeans) to put some breakpoints in your image serving code (e.g. in pluginfile.php) and step through the code that is serving the files to find out what is going wrong.

In reply to Davo Smith

Re: Help!: Alpha version of Grid format for Moodle 2.4

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Dear Davo,

Thank you for responding.  I did change the mime type to text and saw that it was a png file etc.  But the Hex editor idea sounds good.  The snag is the code works fine in 2.3 (with this version only needing to be changed for the 2.4 course format refactoring functionality).

I'll look at XDebug with NetBeans smile - It's strange as the pluginfile.php is core code that is used all over the place and I'm using it the same as other code with the html writer to create the tags.

Thanks again,

Gareth

In reply to Gareth J Barnard

Re: Help!: Alpha version of Grid format for Moodle 2.4

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Tracked the issue down with the Hex Editor (difference between the file downloaded and the one on disk) to the dredded BOM 'EF BB BF' prepending issue.  Have to now find the culprit!

Cheers,

Gareth

In reply to Gareth J Barnard

Re: Help!: Alpha version of Grid format for Moodle 2.4

by Oliver Jackson -

I'm testing the 2.4.0.3 beta from Dec 21st and I can upload and display a PNG image as a grid format section icon but PNG transparency is displayed as a black background.

When using the same image in a label within the same course it displays with correct transparency.

In reply to Oliver Jackson

Re: Help!: Alpha version of Grid format for Moodle 2.4

by Oliver Jackson -

Once I looked a bit further it appears Moodle may have a built in PNG transparency issue.

function convert_image() in /lib/filestorage/file_storage.php does nowhere near as nice a resize as function generate_image_thumbnail() in /lib/gdlib.php.

The latter is used as the site profile picture thumbnail converter and works perfectly with PNG transparency.

Does grid format have to use convert_image() because it's using the filestorage library or could it do its image file conversion with generate_image_thumbnail() on the side?

Average of ratings: Useful (1)
In reply to Oliver Jackson

Re: Help!: Alpha version of Grid format for Moodle 2.4

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Dear Oliver,

Thanks for the information, I had noticed the png issue but had not gotten around to doing something about it or even noting in the readme.

Pragmatically it is a Moodle core issue (tracker currently down to see if an issue aready exists) as one should call the other.  However,  I can see no problem (yet / unless GD2 is not installed) with using the better function to generate the image and then saving it off.  Just requires a bit of coding.

Cheers,

Gareth

Average of ratings: Useful (1)
In reply to Gareth J Barnard

Re: Help!: Alpha version of Grid format for Moodle 2.4

by Ben Kelada -

Hey Gareth great work on finding the PNG bug!

Just wondering if there was ever a 2.3 production ready version of grid format?

does it work with PNG's?

cheers,

Ben

In reply to Ben Kelada

Re: Help!: Alpha version of Grid format for Moodle 2.4

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Dear Ben,

No problem.  The PNG issue has been back ported to 2.3 - please get the latest version from https://github.com/PukunuiAustralia/moodle-courseformat_grid/tree/MOODLE_23_STABLE - however there is a transparency issue which needs working on as you can see from the other posts in this thread.

No production ready version yet - I think Julian will need sufficient feedback from the community that the beta version is stable.

Cheers,

Gareth

In reply to Gareth J Barnard

Re: Help!: Alpha version of Grid format for Moodle 2.4

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Dear all,

I think I have solved the transparent PNG issue (in 2.4 version at the moment), please test:

https://github.com/gjb2048/moodle-courseformat_grid/archive/V2.4.0.5.zip

Cheers,

Gareth

Average of ratings: Useful (1)
In reply to Gareth J Barnard

Re: Help!: Alpha version of Grid format for Moodle 2.4

by Ben Kelada -

Hi Gareth,

in the 2.3 backport lines 29 and 30 of format.php break the code (i think they are for 2.4)

think you could backport the transparency fix and the code fixes, i can test the 2.3 backport

cheers,

Ben

 

In reply to Gareth J Barnard

Re: Help!: Alpha version of Grid format for Moodle 2.4

by Oliver Jackson -

Very nice.

It now maintains the transparancy on any PNG I throw at it.

I'll run it on a couple of larger courses and do some backup/restore testing etc.

Thanks

Oliver