Image in Course Display for each course

Image in Course Display for each course

by Alvaro Corugedo -
Number of replies: 55
Hi everybody:
First of all, I'm just starting big grin

I want to display a selected image for every course when displaying courses in category module. For instance: If the course is about office, display the office logo under the course name.

I guess, I have to modify the table mdl_course to add a new field (ie. called image). Which modules do I have to modify then?

Thank you.
Average of ratings: -
In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by Ger Tielemans -
Also here, best solution would be a dircetory where you drop your images and a dropdown list with the images in that dir on the course overview page in edit-mode..
In reply to Ger Tielemans

Re: Image in Course Display for each course

by Alvaro Corugedo -
Yes ... By now I have included a few things:

1.- A field in mdl_courses called image varchar(100) to keep the image path.

2.- Modified edit.html in /course to have a textbox.

3.- A new string in moodle.php as follows (my lang is spanish):

$string['courseimage'] = "Imagen asociada";

4.- A help file for the helpbutton

Now I want that image displayed in the course summary. Where should I change it?

PD : http://compusof.sl-formacion.com/course/category.php?id=2
In reply to Ger Tielemans

Re: Image in Course Display for each course

by Alvaro Corugedo -
NEW changes:

Now I allow to select the image from a directory. I include a new accumulative CHANGES file.

Hope it's useful

In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by W Page -

Hi!

Thank you for all your help.

Just wanted to ask where the "images" directory should be placed inside of the "MOODLE" directory.

Should it be,

/moodle/images/ ??

If this is correct, I got this message by placing it there,

Associated Image:  Unable to open ./images/

Cannot wait to see it work on my test site.

WP1

In reply to W Page

Re: Image in Course Display for each course

by Alvaro Corugedo -
Hi:

I created a directory called images below /moodle/course. (As edit.html and edit.php are found in the course directory).

Best Regards
In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by W Page -

OK after playing with it a while I see the path should be,
/moodle/course/images

Now this may seem like a silly question but on what page can I see the images in the courses.  I have corses in the middle column of my home page but there are no images.  Where can I find them?

WP1

In reply to W Page

Re: Image in Course Display for each course

by Alvaro Corugedo -
This images are displayed when listing them after selecting a cetgory in the main page

Example

http://compusof.sl-formacion.com/course/category.php?id=2

I'll check if whe can use them also in the main page.
In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by W Page -

Hello!

Thanks you for your help and such a nice script.

Would you please take a look at the following link and tell me if you can find a course list with the images on the site.  Somehow I am not navigating to the correct page.   Or, I am doing something else wrong,

http://s94988317.onlinehome.us/moodle/

I think I made the appropriate script changes as per instructions.  See the result in the image below.

Thanks again,

WP1

Attachment course_edit_img.jpg
In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by W Page -

Hi!

Thanks for all of your help. 

At this point I would just like to get the images to display on the "Course" list page under their individual categories via the "drop down" window like on your site.

Any more thoughts as to why I cannot see the images?

WP1

In reply to W Page

Re: Image in Course Display for each course

by Alvaro Corugedo -
I have tested it in my test page using standardwhite, standardlogo and standard themes and it does work. It works with a heading format that shows nes items .. I'll check the same changes for your diaplay format.
In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by W Page -

Thanks!

It is still puzzling to me why I cannot still see the images on the course list pages.

I will go over the steps again.

WP1

In reply to W Page

Re: Image in Course Display for each course

by Alvaro Corugedo -
Change in your test site the tipe of front page you want from lis of courses to display news ... an that's it
In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by W Page -

Hello!

Thank you for hanging in there with me. 

I changed the front page to only display "news" but I still cannot see the images on the course list page.  This is really puzzling.

 An example of the category page with the course listings I am referring to is below.

Is anyone else having this problem after following the instructions??

BTW, I made the following changes in the script for "course/edit.html" just to get the words to align with the words above.

 <tr valign=top>
  <td align=right><P><?php  print_string("courseimage") ?>:</td>
 <td>
 <?php
 $pathofimages = "./images/";
 $dir_handle = @opendir($pathofimages) or die("Unable to open $pathofimages");
 echo "<select name=\"image\" > ";
 while ($imagefile = readdir($dir_handle)) {
  if($imagefile == "." || $imagefile == ".." )
   continue;
  echo "<option value=$imagefile>$imagefile</option>";
 } ;
 closedir($dir_handle);
  echo "</select>";
 ?>
  <?php  helpbutton("courseimage", get_string("courseimage")) ?>

  </td>
 </tr>

 <tr valign=top>
  <td align=right><P><?php  print_string("courseimagealt") ?>:</td>
  <td><input type="text" name="alternate" maxlength="100"  size="50" value="<?php  p($form->alternate) ?>">
  <?php  helpbutton("courseimagealt", get_string("courseimagealt")) ?>
  </td>
 </tr>

Attachment category_course_page.gif
In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by W Page -

That would be neat.  Please post when you determine how to do it.

WP1

In reply to W Page

Re: Image in Course Display for each course

by Alvaro Corugedo -
Think I got it working. I include an explanation on how I did it in the attached file.

Regards
In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by Jon Bolton -
Picture of Particularly helpful Moodlers Picture of Testers
This is a really useful modification - Martin, will this be available as standard for future releases.

One question - I have more than one course in a category listing. I've included a logo for one of them, but I'm getting a blank image for the other courses. See http://learningcentre.baillie.org.uk/course/category.php?id=1, for example.

Is there a way I can show ...
either: no image for courses with no image (preferred option)?
or: a default image for all courses, but the default can be changed for some courses?

Thanks
In reply to Jon Bolton

Re: Image in Course Display for each course

by W Page -

Hi!

TO:   Jon Bolton

Check out the updated script which is in another post of   Alvaro's as "changes-2.txt".  I think this takes care of that problem. 

Also, which version of MOODLE are you using v1.1.1 or developmental v1.2?  I cannot get the images to visualized.  I am wondering if this has something to do with the version I am using.

WP1

In reply to W Page

Re: Image in Course Display for each course

by Bryan Williams -

WP,

What would happen if you created an images directory in the webroot, rather than within Moodle, making sure chmod is set to something like 777.  Alvaro's script is forgiving enough that your image calls are being ignored, rather than sending you an error message.  Jon's earlier problem was probably something in the path of the two images not appearing that needed fixing (did not look at changes-2.txt).  It does not appear that on your site the images are even trying to load.  thoughtful

In reply to W Page

Re: Image in Course Display for each course

by Jon Bolton -
Picture of Particularly helpful Moodlers Picture of Testers

Thanks, I'd noticed Alvaro's post and had already made the changes.

I'm using both versions of Moodle … 1.1.1 in a live enviroment and 1.2 in a test environment. The images work well in both - see http://learningcentre.baillie.org.uk/course/category.php?id=1

I'm not sure why you're having the problems - the only thing that I did noticed in your step-by-step post of what you had done, there was no mention of making changes to /course/edit.php. You need to insert

$form->image = image;

at line 111. This change allows to put the name of the selected image in the DB.

In reply to Jon Bolton

Re: Image in Course Display for each course

by W Page -

Hi!

Thanks for responding.

I just checked.  "$form->image = image;" is at line 111 in "course/edit.php".  Also, all the images are in the proper place (in the field "image" in the "course" table). 

I will just start all over and go step by step again.  Hopefully I can figure this out since I really want to utilize this feature.

WP1

In reply to W Page

Re: Image in Course Display for each course

by W Page -

Hi Everyone!

Well I just had to keep fiddling with it.  I was able to get only one image to display for only one course.  I was able to get this one to display by  not keeping the script (noted just below this paragraph) at line 1152 in "course/lib.php" but by moving it after the requested teacher information in the course block area which was line 1227 in "course/lib.php".

echo "<br><img src=\"/images/$course->image\" alt=\"$course->alternate\" title=\"$course->alternate\"><br><br>";

Please check the following link,
http://s94988317.onlinehome.us/moodle/

Anyone have any suggestions as to how I can correct this problem?

Thanks again in advance for any help anyone can give me with this.

WP1

Below is the code block area I am referring to and where I inserted the above line, 
===========================================

print_simple_box_start("center", "$width", $THEME->cellcontent, 5, "coursebox");

$linkcss = $course->visible ? "" : " class=\"dimmed\" ";

echo "<table width=\"100%\">";
echo "<tr valign=top>";
echo "<td valign=top width=\"50%\" class=\"courseboxinfo\">";
echo "<p><font size=3><b><a title=\"".get_string("entercourse")."\"
$linkcss href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a></b></font></p>";
if ($teachers = get_course_teachers($course->id)) {
echo "<p><font size=\"1\">\n";
foreach ($teachers as $teacher) {
if ($teacher->authority > 0) {
if (!$teacher->role) {
$teacher->role = $course->teacher;
}
$fullname = fullname($teacher, isteacher($course->id)); // is the USER a teacher of that course
echo "$teacher->role: <a href=\"$CFG->wwwroot/user/view.php?id=$teacher->id&course=$site->id\">$fullname</a><br />";
echo "<br><img src=\"./images/$course->image\" alt=\"$course->alternate\" title=\"$course->alternate\"><br><br>";
}
}
echo "</font></p>";
}

In reply to W Page

Re: Image in Course Display for each course

by W Page -
Hello All!

OK I am still "fiddling" with this particular script.

As I pointed out in the previous post. Before I moved the script line no image would display even if a teacher was assigned to a course.  After I moved the script line which is in "course/lib.php" only one image displayed for one course. None of the other images displayed for any of the other courses.  I had also previously added a teacher to that particular course before moving the script line. I could not see any relationship between adding the teacher and seeing the image at the time.

Later this evening I added a teacher to two other courses . All of a sudden the images displayed. But, only if the course had a teacher added.

Any course I have not added a teacher to still does not have an image displayed although I added an image in the "Edit course settings" page.

The image should display even if a teacher is not assigned to the course.

Can anyone explain why this is happening??

WP1


In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by W Page -

Hello!

I am very interested in this modification.  I attempted to follow the instructions but I code is displaying on the course edit page.  Also I did not know if there was some code which should be placed in the "courseimage.html" & "courseimagealt.html" files so I left their content blank.  I placed the steps I follow below with some indication of where I had inserted code in the significant files.  I attached an image of how the code is displaying on the corse edit page and how the two fields I added to the database look as well so you would have as mush information as possible.

I hope you can help me out with this.

WP1

--------------------------------------

STEP 1

Inserted two fields into the "mdl_course" table with the values indicated in the instructions.  Please see the lower part of the image below. 

STEP 2

Inserted code beginning at line 28 in the "course/edit.html".  The insrted code is in blue.

<tr valign=top>
 <td align="right"><P><?php  print_string("shortname") ?>:</td>
 <td><input type="text" name="shortname" maxlength="15"  size="10" value="<?php  p($form->shortname) ?>">
    <?php  helpbutton("courseshortname", get_string("shortname")) ?>
    <?php  if (isset($err["shortname"])) formerr($err["shortname"]); ?>
 </td>
</tr>

<tr valign=top>
  <td><P><?php  print_string("courseimage") ?>:</td>
  <td><input type="text" name="image" maxlength="100"  size="50" value="<?php  p($form->image) ?>">
 < ?php  helpbutton("courseimage", get_string("courseimage")) ?>
  </td>
 </tr>
 <tr valign=top>
  <td><P><?php  print_string("courseimagealt") ?>:</td>
  <td><input type="text" name="alternate" maxlength="100"  size="50" value="<?php  p($form->alternate) ?>">
  <?php  helpbutton("courseimagealt", get_string("courseimagealt")) ?>
  </td>
 </tr>

<tr valign=top>
 <td align="right"><P><?php  print_string("summary") ?>:</td>
 <td><?php
        print_textarea($usehtmleditor, 10, 50, 660, 200, "summary", $form->summary);
        helpbutton("text", get_string("helptext"));
        if (isset($err["summary"])) formerr($err["summary"]);
    ?>
 </td>
</tr>

STEP 3

Placed the following code at line  - 797 - in the "/lang/en/moodle.php" (My language is english).  The insrted code is in blue.

$string['todaylogs'] = 'Today's logs';
$string['courseimage'] = "Associated Image";  
$string['courseimage'] = "Alternate text";  
$string['toomanytoshow'] = 'There are too many users to show';

STEP 4

I changed line  - 1152 - in "/course/lib.php".  The insrted code is in blue.

if ($courses) {

foreach ($courses as $course) {

echo "<br><img src=\"$course->image\" alt=\"$course->alternate\" title=\"$course->alternate\"><br><br>";

$linkcss = $course->visible ? "" : " class=\"dimmed\" ";

$moddata[]="<a $linkcss title=\"$course->shortname\" ".

"href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>";

$modicon[]=$icon;

}

$fulllist = "<p><a href=\"$CFG->wwwroot/course/index.php\">".get_string("fulllistofcourses")."</a>...";

} else {

$moddata = array();

$modicon = array();

$fulllist = get_string("nocoursesyet");

}

}

STEP 5

Created two files named  - "courseimage.html" & "courseimagealt.html" for Helpfiles  /lang/en/help.  However, I do not know what code should be used in these file if any.  Are they to be blank "html" files?

Attachment course_field_mysql_combo.jpg
In reply to W Page

Re: Image in Course Display for each course

by Alvaro Corugedo -
Hi.. is there an extra blank space in line 35 of edit.html .? (seen in image) < ? .... should be without blank between < and ?.

courseimage.html and courseimagealt.html are just simple html files whith help content for the popup windows.

Regards
In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by W Page -

Thank you for your help.

I looked back at the original instructions you posted and found the following,

1.  The space you pointed out to me (which corrected the problem) was in the original instructions as,

Changes in course/edit.html (line 28)
---------------------------------------

Added:

 <tr valign=top>
  <td><P><?php  print_string("courseimage") ?>:</td>
  <td><input type="text" name="image" maxlength="100"  size="50" value="<?php  p($form->image) ?>">
 <              ?php  helpbutton("courseimage", get_string("courseimage")) ?>
  </td>
 </tr>
 <tr valign=top>
  <td><P><?php  print_string("courseimagealt") ?>:</td>
  <td><input type="text" name="alternate" maxlength="100"  size="50" value="<?php  p($form->alternate) ?>">
  <?php  helpbutton("courseimagealt", get_string("courseimagealt")) ?>
  </td>
 </tr>

When editing a course there are two new fields below SHORTNAME of the course

2.  the name "courseimage" was repeated in the name file in the instructions as,

changes in /lang/es/mooodle.php (My language is spanish)
---------------------------------------

Added (seems to be ordered by name) in line 797:

 $string['courseimage'] = "Imagen asociada";  Associated Image
 $string['courseimage'] = "Texto alternativo";  Alternate text

It should have been (I think)

$string['courseimage'] = "Imagen asociada";  Associated Image
$string['courseimagealt'] = "Texto alternativo";  Alternate text

But I have another problem.

I cannot see an image on the course list page.  This is an example of how I put the

/homepages/20/g12345678/htdocs/moodle/pix/course/course_test_img_01.jpg

I am wondering if I do not have the correct course layout for the image to display.  I am looking forward to getting this script to work.  Adds a nice touch to MOODLE.

WP1

In reply to W Page

Re: Image in Course Display for each course

by Alvaro Corugedo -
Hi:

1.-
Sorry for the mistake sad


2.- Should read courseimagealt .. you are right

----
I did not include the full path on the server ... just write the path from where moodle resides :

/pix/course/course_test_img_01.jpg

Alvaro

PD: I Shall correct it and post it again. smile. I'm still working on it to make it more user friendly
In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by Ger Tielemans -

Nice hack, thanks....

Our teachers wish to differentiate in icons for the resources (for example a potatoe for a hotpotatoes-resource, a globe for a website-resource, a book for an online dictionary, etc.)

Can you create here also a "choose your icon from a drop-down-box"? glimlach

In reply to Ger Tielemans

Re: Image in Course Display for each course

by W Page -

Alvaro & Jon  I still need your help.  If you have a moment please read these sequential posts,
http://moodle.org/mod/forum/discuss.php?d=4793&parent=23240
http://moodle.org/mod/forum/discuss.php?d=4793&parent=23345

Also I would like to give my vote to a feature referred to above by "Ger".  That would be a neat feature that again adds to the customization of MOODLE.  It would allow admin/teachers to easily choose the icons they want for a course and not just the pre-assigned ones from moodle.

WP1

In reply to W Page

Re: Image in Course Display for each course

by Alvaro Corugedo -
Sorry for being away.I did not have time.

About images for a course and different images for resources in a course/seminar... I have both things in mind.
I started to include images for the course. What I sent was ok for me ... but you are right, I need to assign a teacher in order to have the image displayed. I plan to check it out and add some error handling.

In future i will try to change also images for resources..(http://moodle.org/mod/forum/discuss.php?d=3847) if nobody does it first.

Salu2

In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by Alvaro Corugedo -
To make an image appear even if a teacher is not set, just take the line out of the foreach teacher sobroutine and before the if course->guest.
In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by W Page -

Thanks Alvaro,

It is working fine now with or without a teacher being assigned to a course.
http://s94988317.onlinehome.us/moodle/

I thank everyone for their patience and persistence, especially you Alvaro for such a nice feature.  Really dresses up the site.

WP1

In reply to W Page

Re: Image in Course Display for each course

by Alvaro Corugedo -
Hi:

I'm right now modifying it again to include some checks:

1.- Allow to put a "No image" for a course (just done)
2.- Check out the existence of the image (just in case it was deleted).
3.- Adding a selected feature for the current image
4.- maybe a default one?

Few questions:

Is there anything similar to choose_from_menu() for files or should it be written. In this case, could it be included in weblib.php (I read somewhere that this cannot be done).

What should I do to have this code included in a further version of moddle?

What else should do this code?? Suggestions welcomed
Thank you
In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by W Page -

INCLUDE ISSUES

1.- Allow to put a "No image" for a course (just done)
Yes I think that is a good choice to add.  I was going to create a transparent gif if I did not want to have an image with a course.  Your idea would be much better.

2.- Check out the existence of the image (just in case it was deleted).
Yes

3.- Adding a selected feature for the current image
I am not sure what you mean by this feature.

4.- maybe a default one?
This would be good along with the "no Image" feature you addressed in # 1.

QUESTIONS

  • Is there anything similar to choose_from_menu() for files or should it be written. In this case, could it be included in weblib.php (I read somewhere that this cannot be done).  I am not a programmer so I do not know the answer to this

  • What should I do to have this code included in a further version of moddle?  Let Martin know about it via e-mail (I guess that is the procedure).   I mentioned it on another thread but did not get a response from him about it.
    Countdown to 1.2 and beyond
    http://moodle.org/mod/forum/discuss.php?d=5158
  • What else should do this code?? Suggestions welcomed  The script adds code and does not change code so I would suspect it would not be too much of a problem to add.  Now that the image/teacher connection  has been resolved  along with the addition of a no image choice, I think the script is ready for "prime time". 

Again thanks for a really nice script.

WP1

In reply to W Page

Re: Image in Course Display for each course

by Alvaro Corugedo -
Point 3 refers to "option value selected". I hope I have changes done tonight.
Regards
In reply to W Page

Re: Image in Course Display for each course

by Alvaro Corugedo -
New changes (Acummulative):

1.- I do allow not to set/unset an image for a course.
2.- I check for the content of image field in course to prevent the use of an empty img tag.
3.- The option value selected works and shows the current image in DB.

Enjoy big grin
In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by W Page -

Hi Alvaro!

I noticed that when I went back to the "Settings" page for a course the image "drop down" window went back to the first image by alphabet in the "course/images" directory.  When I made the changes I wanted to and saved the page, that image and not the image I had previously saved for that course would display on the Course List page.

Do the changes that you made correct this?  In other words, even if the Course Settings page is revisited will the images which was previously chosen be saved with the rest of the information or does the new image which appears in the image window display instead?

I am sorry I did not see this before you made the more recent changes in the script.

I have not made the most recent changes in the script indicated in "changes-3.txt".

WP1

In reply to W Page

Re: Image in Course Display for each course

by Alvaro Corugedo -
Yes it does big grin (option value selected)
In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by W Page -

Hi Alvaro!

Made the updated changes in "Cambios 3"

All of the images have disappeared and there is only a box for the image. See below.

Also the following message on the Course "Setting" page.
Parse error in /homepages/22/d12345678/htdocs/moodle/course/edit.html on line 41

You can check it out at,
http://s94988317.onlinehome.us/moodle/

What did I do wrong??

Line 41 is the line in bold/red below,

<tr

valign=top>
<td><P><?php print_string("courseimage") ?>:</td>
<td>
<?php
$pathofimages =
"./images/";
$currentcourseimage = $course->image;
$dir_handle = @opendir($pathofimages) or die("Unable to open $pathofimages");
echo "<select name=\
"image\">";
echo "<option value=\
"\">";
print_string("coursenoimage");
echo "<option value=\
"\">----------</option>";
while ($imagefile = readdir($dir_handle)) {
if($imagefile == "." || $imagefile == ".." || )
continue;
if($imagefile == $currentcourseimage) {
echo "<option value=\
"$currentcourseimage\" selected>$currentcourseimage</option>";
} else {
echo "<option value=$imagefile>$imagefile</option>";
};
} ;
closedir($dir_handle);
echo "</select>";
?>
<?php helpbutton(
"courseimage", get_string("courseimage")) ?>

</td>
</tr>

<tr valign=top>
<td><P><?php print_string("courseimagealt") ?>:</td>
<td><input type="text" name="alternate" maxlength="100" size="50" value="<?php p($form->alternate) ?>">
<?php helpbutton(
"courseimagealt", get_string("courseimagealt")) ?>
</td>
</tr>
Attachment post_cambios_3.jpg
In reply to W Page

Re: Image in Course Display for each course

by Alvaro Corugedo -
Try to change $pathofimages to /course/images
In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by W Page -

Hi Alvaro!

I figured it out and the script is working again,

I think in "edit.html".

               if($imagefile == "." || $imagefile == ".." || )


should be,

                if($imagefile == "." || $imagefile == ".." )

The extra "||" should be removed.


I think in "lib.php".

    if($course->image != "") {
 echo "<br><img src=\"./course/images/$course->image\" alt=\"$course->alternate\" title=\"$course->alternate\"><br><br>";
    }

should be,

    if($course->image != "") {
 echo "<br><img src=\"./images/$course->image\" alt=\"$course->alternate\" title=\"$course->alternate\"><br><br>";
    }

The ./course/images/ should be changed back to ./images/

Take a peak at,
http://s94988317.onlinehome.us/moodle/course/category.php?id=1

WP1

In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Hi, Alvaro.

Thanks for the contribution - I'll try to get it in when the code settles down.

One thing it still needs - big images should be scaled down. I guarantee the first thing teachers will be doing is uploading images there from their brand-new 6 megapixel cameras. smile
In reply to Martin Dougiamas

Re: Image in Course Display for each course

by W Page -

Thats Great Martin!

WP1

In reply to Martin Dougiamas

Re: Image in Course Display for each course

by Alvaro Corugedo -
Hi Martin.

Thank you.

Which would you consider the maximum size for an image in this case?.

Saludos big grin
In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Assume there is a configuration value like $CFG->courseimagesize and it defaults to, oh, how does 150 pixels sound?
In reply to Martin Dougiamas

Re: Image in Course Display for each course

by Alvaro Corugedo -
Thank you. I just have done it. Now it displays the size in the selection box after the filename and when displaying it resizes proportionaly the image.

I'm going to test it and as soon I have finished I'll post Changes version 4.

How do you apply changes to a current installation (patch)?

Saludos
In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
The best way to post contributions is in the form of a context diff.

On Unix you can use diff -c or (if you use CVScvs diff -c.  These should be against the very latest development code.

I almost never just apply these straight in - I usually go through and hand-merge the code as part of my code review - but it's the best format for me to understand what changes you made.
In reply to Martin Dougiamas

Re: Image in Course Display for each course

by Alvaro Corugedo -
Now includes image resizing smile
In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by W Page -

Hi Alvaro,

PROBLEM 1

I think in "/moodle/config.php"

   $CFG->courseimagesize = 150

should be,

  $CFG->courseimagesize = '150';

PROBLEM 2

I am getting an error message about the following line in "/course/lib.php"

   $courseimgsz = getimagesize($imagen);

Warning: getimagesize: Unable to open '/srv/www/htdocs/moodle/course/images/measure_tools.gif' for reading. in /homepages/30/d94988299/htdocs/moodle/course/lib.php on line 1181

PROBLEM 3

I think the path which is in "course/lib.php"(noted in blue should be for the present site), but even if this is changed to the present site path the error noted in Problem 2 still occurres.

  if ($course->image) {
                $imagen = "/srv/www/htdocs/moodle/course/images/" . $course->image;
                $courseimgsz = getimagesize($imagen);
                $hscale = $courseimgsz[0] / $CFG->courseimagesize;
                $wscale = $courseimgsz[1] / $CFG->courseimagesize;
                if (($hscale > 1) || ($wscale > 1)) {
                        $scale = ($hscale > $wscale)?$hscale:$wscale;
                } else {
                        $scale = 1;
                }
                $newwidth = floor($courseimgsz[0] / $scale);
                $newheight= floor($courseimgsz[1] / $scale);
                echo "<br><img src=\"./course/images/$course->image\" width=\"$newwidth\" height=\"$newheight\" alt=\"$course->alternate\" title=\"$course->alternate\"><br><br>";
    }

SUGGESTION

  • To provide files for scripts which will automatically size images to a certain size and one which will allow any size image. 
  • Or provide the choice to have an image resized to a pre determined size or not. 

Different course directors may want images of diferent sizes with a lot of text on the right about the course.

WP1

In reply to W Page

Re: Image in Course Display for each course

by Alvaro Corugedo -
Hi:

Problem 1 : Yes.

Problem 2: function getimagesize() does not find the file. You have to change the image variable to whatever your path is. My problem is that I'm using two different platforms (one for testing -my laptop- and another for production, and instllations are different).

Problem 3: same as above.

Suggestions: The size is set by admin in config.php. I do not think any other person should be able to modify it. Martin's suggestion was 150 pixels, but you may change to whatever you want. In case the image is smaller the script uses it's actual size but limits the bigger ones. Actually I use a size of 200.

Saludos
In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by Alvaro Corugedo -
Just in case. I include the diff files. It is working on my test site.

Salu2
In reply to Alvaro Corugedo

Re: Image in Course Display for each course

by W Page -

Hi Alvaro,

All I can say is wonders never cease.  I was pulling my hair out over this script.  I could not understand why I kept getting an error message no matter how I changed the direct path.  Well for some reason I clicked on the "course/images/" directory within my FTP client.  The file would not open.   I kept getting a message when I tried to open the directory -- 550 permission denied.  I checked the CHMOD and it was 644.  I could not figure out what was going on.  Luckily I had copies of all of the images on HD so I changed the name of the images directory (it still would not open) and created a new "images" directory.  The new directory opened and I was able to upload the image files again.  Guess what?  The images reappeared.

The web host that hosts this installation of MOODLE allows its users to utilized SSH.  Soooooo I used SSH and I was able to reach and open the old "images" directory which had been renamed and easily opened it (checked the directory).  I went back into the FTP client and was now able to get into the old "images" directory.

The images are displaying now.  Also I adjusted the image size to 200.  Looks great.

But
  • can anyone explain to me what happened?
  • can anyone suggest a way to deal with this problem in the future?

Again Alvaro, thanks for a nice script.

WP1

In reply to Martin Dougiamas

Re: Image in Course Display for each course

by Ger Tielemans -

Martin, can you implement the same "choose your image from a (directory)list" for the resources

Teachers paste ressources on the sections.and they are begging for that option smile

(To give their students some clou about the typeof the resources)