Merge branch 'w21_MDL-18763_m23_avatar512' of git://github.com/skodak/moodle

This commit is contained in:
Sam Hemelryk 2012-05-28 16:50:46 +12:00
commit a2aba3f612
5 changed files with 47 additions and 11 deletions

View File

@ -3612,7 +3612,7 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null) {
}
// fix file name automatically
if ($filename !== 'f1' and $filename !== 'f2') {
if ($filename !== 'f1' and $filename !== 'f2' and $filename !== 'f3') {
$filename = 'f1';
}
@ -3625,20 +3625,28 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null) {
redirect($theme->pix_url('u/'.$filename, 'moodle')); // intentionally not cached
}
if (!$file = $fs->get_file($context->id, 'user', 'icon', 0, '/', $filename.'/.png')) {
if (!$file = $fs->get_file($context->id, 'user', 'icon', 0, '/', $filename.'/.jpg')) {
// bad reference - try to prevent future retries as hard as possible!
if ($user = $DB->get_record('user', array('id'=>$context->instanceid), 'id, picture')) {
if ($user->picture == 1 or $user->picture > 10) {
$DB->set_field('user', 'picture', 0, array('id'=>$user->id));
if (!$file = $fs->get_file($context->id, 'user', 'icon', 0, '/', $filename.'.png')) {
if (!$file = $fs->get_file($context->id, 'user', 'icon', 0, '/', $filename.'.jpg')) {
if ($filename === 'f3') {
// f3 400x400px was introduced in 2.3, there might be only the smaller version.
if (!$file = $fs->get_file($context->id, 'user', 'icon', 0, '/', 'f1.png')) {
$file = $fs->get_file($context->id, 'user', 'icon', 0, '/', 'f1.jpg');
}
}
// no redirect here because it is not cached
$theme = theme_config::load($themename);
$imagefile = $theme->resolve_image_location('u/'.$filename, 'moodle');
send_file($imagefile, basename($imagefile), 60*60*24*14);
}
}
if (!$file) {
// bad reference - try to prevent future retries as hard as possible!
if ($user = $DB->get_record('user', array('id'=>$context->instanceid), 'id, picture')) {
if ($user->picture > 0) {
$DB->set_field('user', 'picture', 0, array('id'=>$user->id));
}
}
// no redirect here because it is not cached
$theme = theme_config::load($themename);
$imagefile = $theme->resolve_image_location('u/'.$filename, 'moodle');
send_file($imagefile, basename($imagefile), 60*60*24*14);
}
send_stored_file($file, 60*60*24*365, 0, false, array('preview' => $preview)); // enable long caching, there are many images on each page

View File

@ -166,19 +166,27 @@ function process_new_icon($context, $component, $filearea, $itemid, $originalfil
if (function_exists('imagecreatetruecolor') and $CFG->gdversion >= 2) {
$im1 = imagecreatetruecolor(100, 100);
$im2 = imagecreatetruecolor(35, 35);
$im3 = imagecreatetruecolor(512, 512);
if ($image->type == IMAGETYPE_PNG and $imagefnc === 'imagepng') {
imagealphablending($im1, false);
$color = imagecolorallocatealpha($im1, 0, 0, 0, 127);
imagefill($im1, 0, 0, $color);
imagesavealpha($im1, true);
imagealphablending($im2, false);
$color = imagecolorallocatealpha($im2, 0, 0, 0, 127);
imagefill($im2, 0, 0, $color);
imagesavealpha($im2, true);
imagealphablending($im3, false);
$color = imagecolorallocatealpha($im3, 0, 0, 0, 127);
imagefill($im3, 0, 0, $color);
imagesavealpha($im3, true);
}
} else {
$im1 = imagecreate(100, 100);
$im2 = imagecreate(35, 35);
$im3 = imagecreate(512, 512);
}
$cx = $image->width / 2;
@ -192,6 +200,7 @@ function process_new_icon($context, $component, $filearea, $itemid, $originalfil
imagecopybicubic($im1, $im, 0, 0, $cx - $half, $cy - $half, 100, 100, $half * 2, $half * 2);
imagecopybicubic($im2, $im, 0, 0, $cx - $half, $cy - $half, 35, 35, $half * 2, $half * 2);
imagecopybicubic($im3, $im, 0, 0, $cx - $half, $cy - $half, 512, 512, $half * 2, $half * 2);
$fs = get_file_storage();
@ -220,6 +229,17 @@ function process_new_icon($context, $component, $filearea, $itemid, $originalfil
$icon['filename'] = 'f2'.$imageext;
$fs->create_file_from_string($icon, $data);
ob_start();
if (!$imagefnc($im3, NULL, $quality, $filters)) {
ob_end_clean();
$fs->delete_area_files($context->id, $component, $filearea, $itemid);
return false;
}
$data = ob_get_clean();
imagedestroy($im3);
$icon['filename'] = 'f3'.$imageext;
$fs->create_file_from_string($icon, $data);
return $file1->get_id();
}

View File

@ -321,6 +321,9 @@ class user_picture implements renderable {
} else if ($this->size === true or $this->size == 1) {
$filename = 'f1';
$size = 100;
} else if ($this->size > 100) {
$filename = 'f3';
$size = (int)$this->size;
} else if ($this->size >= 50) {
$filename = 'f1';
$size = (int)$this->size;

BIN
pix/u/f3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -2,6 +2,11 @@ This files describes API changes in /theme/* themes,
information provided here is intended especially for theme designer.
=== 2.3 ===
optional changes:
* add new u/f3.png image when theme contains customised f1 and f2 default user images
=== 2.2 ===
required changes: