Jpg display module

Jpg display module

by J B -
Number of replies: 40

Users have been asking me for a simple photo display feature, and I couldn't find anything available that made this easy, so wrote this module to display thumbnails and photos.

Feed it a directory and it displays the jpg's as thumbnails above one fullsize image. If there are no thumbnails in the directory ./jpgs_tn/ they are created. Click on thumbnails to change the image. It works with postgres but other database users *may* need to tweak the sql.

It mostly works, but I was hoping for a simple way to make /files/index.php allow me to select a directory - can anyone can help me out with this please, as I don't want to reinvent any wheels? As yet there is no option to do ordering other than renaming the files and no auto-progression, but that may come if nothing better surfaces soon - right now it is about as simple as it could get. Of course I will be grateful for any comments and suggestions, even criticism, but this is my first moodle module, so go easy smile

Average of ratings: -
In reply to J B

Re: Jpg display module

by J B -
Following some testing and modifications, here is a much nicer and more useful version of this module. It now has directory selection,more limited logging, large images are scaled down on the page, and clicking on the current image brings up the next one.
In reply to J B

Re: Jpg display module

by Colin McQueen -
Hi

This looks interesting

When I try this it fails with an error:-

"Could not add a new instance of slideshow"

Using this latest version with Moodle 1.6 development (2005101200) and MySQL Anyone got it working with this combo?
In reply to Colin McQueen

Re: Jpg display module

by Art Lader -

It really does sound very interesting! Hope development will continue.

-- Art

In reply to Art Lader

Re: Jpg display module

by J B -
Thanks for your comments, I hope the module can be of some use. Of course I am still open to suggestions from anyone who manages to get it working!

In the attached zip I have had a look at the MySQL sql and made a couple of small changes to the code, but I have no MySQL'ed Moodle to test on so I can 't tell if it works - however the module makes very little demand on the database, I am sure that fixing it would be trivially simple for someone who had a little understanding of such things!

The module works fine on 1.5.3 and on my 1.6dev installation( also 2005101200!), but I develop and use the module with moodle on Postgresql, variously with IIS 6 and apache. You can see it working here.
In reply to Colin McQueen

Svar: Re: Jpg display module

by Anders Berggren -

Hi Colin,

I have encountered exactly the same problem.
1.6 dev and MySQL.
Cheers, Anders
In reply to Anders Berggren

Jpg display module on MySQL!

by J B -
Thanks for your patience, people. OK, I have installed a local moodle running on MySQL, hacked at db/mysql.sql again and did find what could actually be classed as an obvious mistake!

The JPG slideshow module now installs - and works - under MySQL as well as PostgreSQL.

Now all I have to do is make sure I attach the right file ...
In reply to J B

Re: Jpg display module on MySQL!

by Andy Tagliani -
Nice modul, thanks. I´m not sure but mean you must modify the view.php in line 65

Thats the original
if (!($tn = opendir($dir.'/'.$slideshow_thumbdir))){

Thats my modification
if (!($tn = opendir($dir.'/'.$slideshow_thumbdir ))){

Bye Andy
In reply to Andy Tagliani

Re: Jpg display module on MySQL!

by J B -
Hi Andy,

I am glad you like it, hope it helps.

        if (!($tn = opendir($dir.'/'.$slideshow_thumbdir))){
//----------------------------------------------^
But why the extra space there - does the script fail without it on your server? What setup are you using?
In reply to J B

Re: Jpg display module on MySQL!

by Andy Tagliani -
Hi James

It was a error from the first installation (with old files) of this module. There was the solution, the extra space comment out the error. Now all works fine. A little optical problem is, i want a space between the left and right border. Anyway, the modul works perfect, thanks much!

I testet it one moodle 1.5.3 and 1.6dev and on both version slideshow works fine!
Bye Andy
In reply to Andy Tagliani

Re: Jpg display module on MySQL!

by Colin McQueen -
I have spent ages trying to get this working here but at last I have ...

First I was using Moodle 1.6 MySLQ and early module versions with no joy.
- fixed this by using Moodle 1.53 instead and the later version working with
MySQL not just postgresql.

Second I got the error
opendir ... failed to open dir: Invalid argument in ...
mod\slideshow\view.php on line 65
and no thumbs would be appear
- fixed this by making sure I had the PHP GD extension installed wink
The thumbnail directory was created but no thumbnails of course.
Silly me!

Perhaps a message saying "No thumbs present is GD installed?" would help?

Third I still get the error above but now it works. Changing line 65
if (!($tn = opendir($dir.'/'.$slideshow_thumbdir ))){
by having a space or not makes no difference here but it doesn't prevent the module working.

Thanks, nice module. approve
In reply to Colin McQueen

Re: Jpg display module on MySQL!

by J B -
Colin,
Thanks for the suggestion - you are absolutely right. I have added a fallback behaviour so that the filenames are displayed instead of thumbnails rather than a warning in case GD is not installed, also I have changed the code at line 65 to avoid those error messages.

I am keeping the latest version here: zip.gif latest slideshow.zip
In reply to J B

Re: Jpg display module on MySQL!

by Andy Tagliani -
Hello all

I will tell you for what we take this module in one case. In our Major course where every user have access, i do upload all userpics (100x100 pixel) and so they can search all pics from all user. They love it, because its the first time they can see all on one place.

Next Case i offer Screenshots for a tool or a problem e.g., it works fantastic. In another case they course show pictures from their trip in Austria.

Thanks again James!
Andy

P.S. Anders, i know what u mean, and really this will be a fantastic future AddOn. For the moment, i make a side e.g. publisher, word, html-editor and make a screenshot with the description. Its not the best way, but for the moment it works!
In reply to Andy Tagliani

Re: Jpg display module on MySQL!

by J B -
Thanks,

It's good to know that it has been put to good use. I will try to work out a way the module could be used as simply as it is, yet also offer some form of captioning to the teacher.

I have added a string to the language files:
$string['no_GD_no_thumbs'] = 'The GD extension for PHP is not installed, so no thumbnails will be created.';

in case anyone might be so kind as to translate
In reply to J B

Re: Jpg display module on MySQL!

by Julian Ridden -
Two quick things.

1) could I ask that either version numbers or some kind of date string be added to your files. I have been scrolling up and down this forum comparing posting dates trying to ensure I have the latest version of your code. Many thanks.

2) Have I missed something? Just tried to add an instance of your slideshow to a course and got the following error:

"This module cannot be added to this course yet!
(No file found at: ../mod/slideshow/mod.html)"

Any ideas on why I get this?
In reply to Julian Ridden

Re: Jpg display module on MySQL!

by J B -
1) Done. I hadn't bothered previously as it was very much a work in progress.

2) No. I had. There was no file mod.html in a hastily compiled archive.

The latest version is currently kept at: zip.gif latest slideshow.zip
In reply to J B

Re: Jpg display module on MySQL!

by Andy Hawkins -

Latest version looks very useful. Tried using this on 1.5.3+ - but it only shows empty graphics spaces rather than the images themselves. (thumbnails and main image)

The module installed OK and seems to have done all the right things with the files and folders.

Wondering if it is our olde version of MySQL (3.23) and php (4.3.2)?

Andy

PS - like the random picture block with resizing on your site - is that available for download?

In reply to Andy Hawkins

Re: Jpg display module on MySQL!

by J B -
Hi Andy,

Thanks for your comments. The problem might be to do with your php version - I have developed it mostly with PostgreSQL 8 and MySQL 3.23 with php 5.0.2; I have used it across several different environments (1.5.2 through to 1.6, IIS and Apache, Linux and Windows) without this problem.

How are you using "slasharguments"? I have now fixed it to deal with both ways and consolidated some other improvements in the latest version I have just now uploaded; the backup/restore function works (although still needing work TBH) and it can deal with gifs and pngs as well and throws less errors on certain server configs.

zip.gif slideshow.zip

The random picture block is a hack of one that already existed (somewhere here), I will copy my version here, hope it helps:

zip.gif picture_random.zip

In reply to J B

Re: Jpg display module on MySQL!

by Andy Hawkins -

hello James

Thanks for prompt response and links.

Downloaded the 'new' module and overwrote the existing files.

Still no joy.

Slash arguments are set to first option. (apparently better for problems)

If I navigate via files area I can see pics with following url:

http://domain.name/moodle/file.php?file=/216/Still_Photos/School02.JPG

but in slideshow the link from the main picture (to open for printing) is:

http://domain.name/moodle/file.php/216/Still_Photos/School02.JPG

Tried both versions of slash arguments - second one breaks user profile pics. Neither helps with slideshow sad. Thumbnails also not there.

Same with complete uninstall and reinstall. (though strangely it seemed to keep settings where I had set max file size)

We need to update php and mysql anyway - will await this before trying again.

Thanks for your help.

Andy

In reply to Andy Hawkins

Re: Jpg display module on MySQL!

by J B -
That's it then Andy, it is the slasharguments version switching that isn't working. I will have a go at fixing it and let you know asap...
In reply to J B

Re: Jpg display module on MySQL!

by J B -
Actually no, it isn't that, I set up the same slasharguments as you have it, it works fine for me anyway. You have GD working properly? It may be some function that is implemented differently in your older version of php, but I haven't found what it is yet, I don't know what else to suggest. 
In reply to J B

Re: Jpg display module on MySQL!

by Andy Hawkins -

We will be upgrading php and MySQL in a few weeks.

In the meantime I will check whether this thread is relevant ...

http://moodle.org/mod/forum/discuss.php?d=45412#208671

Thanks for your help

Andy

later: No - the thread refers to php_gd2.dll being needed on IIS. We have it. Back to plan B - upgrade. thoughtful

In reply to Andy Hawkins

Re: Jpg display module on MySQL!

by J B -
Hi Andy,
I have just uploaded a new version of this as a file in the zip was corrupted. I actually dont think this is related to your problem, but it might be worth trying a fresh download.
In reply to J B

Re: Jpg display module on MySQL!

by J B -
> Now all I have to do is make sure I attach the right file ...

I really did try ...

This is definitely the one that works best.
Average of ratings: Useful (1)
In reply to J B

Svar: Re: Jpg display module on MySQL!

by Anders Berggren -

Hi,

I still get:
"Could not add a new instance of slideshow"
Win XP and Moodle 1.6

Cheers, Anders

In reply to Anders Berggren

Re: Svar: Re: Jpg display module on MySQL!

by Andy Tagliani -
Anders, don´t overwrite the old files, you must delete them first. Then you install the latest package, try it again! Maybe can be you must delete the cache of your browser.

Bye Andy
In reply to Andy Tagliani

Re: Svar: Re: Jpg display module on MySQL!

by J B -
This is correct, deleting the module should remove the errors from the database.

I haven't "versioned" the changes to date as they have really just been about removing errors - getting it working at all with mySQL has been tough enough for me wink

Replace the files, go to admin > modules > delete "JPG slideshow", then hit /admin again to reinstall the new one.

zip.gif slideshow_002.zip can be considered the first version working on both databases and from now on any changes should be properly managed by version contol in the respective [database].php files.
In reply to J B

Svar: Re: Svar: Re: Jpg display module on MySQL!

by Anders Berggren -

Hi James and Andy,

I followed your instructions and got
the module working. It' is real nice, thanks!

Cheers, Anders leende 
In reply to J B

Svar: Re: Svar: Re: Jpg display module on MySQL!

by Anders Berggren -

Hi again,

I get this when I open a slideshow after having created it:

Warning : opendir(c:\moodledata/46/cannelle/jpgs_data): failed to open dir: Invalid argument in c:\easyphp\www\moodle\mod\slideshow\view.php on line 65

The warning disappears when you do something and
everything seems to work OK after that though.

Cheers, Anders

In reply to Anders Berggren

Re: Svar: Re: Svar: Re: Jpg display module on MySQL!

by J B -
Thanks to you both for pointing this out - I can't say I understand the logic of it, and I haven't been able to reproduce the problem, but the latest version of the file has an extra space in line 65 which, thanks to Andy, apparently cures it!

I will put the latest version here: zip.gif latest slideshow.zip

Happy viewing!
In reply to J B

Re: Svar: Re: Svar: Re: Jpg display module on MySQL!

by Andy Tagliani -
Hi James

This module is wonderful, really great. I´ve still got the problem between the first picture and the left border. My meaning is, the module need a little space, but i can not fix this optical problem for me. Do you have any idea?

Thanks Andy
In reply to Andy Tagliani

Re: Svar: Re: Svar: Re: Jpg display module on MySQL!

by J B -
Andy,

Having developed and always looked at this module in only one or two themes, I never saw the need for the space you describe - just now I have been setting up a couple of themes and I see exactly what you mean.

If you change view.php line 62 to:
  echo'<p style="margin-left : 5px"><a name="tmb">';
and line 91 to:
  echo '<p style="margin-left : 5px"><a name="pic" href="?id='.($cm->id).'&img_num='.fmod($img_num+1,$img_count).'">';
you should get a nice thin margin on the left hand side of the page. I will update the zip next week - unless someone cries "deprecated" or "accessibility" surprise

In reply to J B

Re: Svar: Re: Svar: Re: Jpg display module on MySQL!

by Andy Tagliani -
Thank you very much James, it is perfect!
Bye Andy
In reply to J B

Svar: Re: Svar: Re: Svar: Re: Jpg display module on MySQL!

by Anders Berggren -

Hi all,

I've made all the changes suggested
and now everything works just fine.
In the editor I use it was line 88 instead of 91.
Thanks a lot!
Cheers, Anders
In reply to J B

Svar: Jpg display module lang/sv

by Anders Berggren -

Hi,

Here's the Swedish translation.

Cheers, Anders

In reply to Anders Berggren

Re: Svar: Jpg display module lang/sv

by Andy Tagliani -
Hello

Here´s the german translation
Bye Andy
In reply to Andy Tagliani

Re: Svar: Jpg display module lang/sv

by J B -
Thanks Andy

The new language files are in the latest zip, along with a new fallback behaviour in case GD is not installed. I have also changed the logic around line 65 so as not to upset verbose error messaging.

zip.gif latest slideshow.zip

Cheers

In reply to J B

Svar: Jpg display module

by Anders Berggren -
Just a humble request,
it would be nice if some
textual description could be
added to the images.
In reply to Anders Berggren

Re: Svar: Jpg display module

by J B -
Hi Anders,

First let me say thanks for persisting with this module and for making a translation, which is included in the latest version here, along with a fix for "line 65" and more: zip.gif latest slideshow.zip.

Certainly it would be straightforward enough to display the filename, but introducing the concept of storing metadata would complicate the module enormously. I believe the database module is intended to support a more complex requirement for multimedia display.

I wanted the module to be as simple as possible, and currently it works by reading the contents of the directory rather than looking in the database which is pretty foolproof. It is simpler for the user, who can simply unzip a bunch of images into a directory, and most especially for me, as I don't have to manage the metadata or, worse yet, an easy-to-use interface for the user to work with it. If the images change, the module just works with what it has, I am concerned that using the database to store metadata might cause things to get very messed up if an image is changed, deleted or even added.
In reply to J B

Re: Svar: Jpg display module

by Ger Tielemans -
your nice icon is 16x14 instead of 16x16 like the others.
It sometimes disturbes the view.
I resized it for you smile
Attachment icon.gif
In reply to Ger Tielemans

Re: Svar: Jpg display module

by J B -
Thanks Ger,

I don't know how that one slipped through, bad version control I guess. I created it as 14x16 very early on and thought it had been deleted, but these mistakes have a habit of sticking around.

blush