mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-49627 core: Update uses of generate_image_thumbnail
This removes the need to write tempfiles in these locations.
This commit is contained in:
parent
b7067f065e
commit
2b53b13ff7
3 changed files with 5 additions and 16 deletions
|
@ -384,25 +384,19 @@ class file_storage {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
require_once($CFG->libdir.'/gdlib.php');
|
require_once($CFG->libdir.'/gdlib.php');
|
||||||
|
|
||||||
$tmproot = make_temp_directory('thumbnails');
|
|
||||||
$tmpfilepath = $tmproot.'/'.$file->get_contenthash();
|
|
||||||
$file->copy_content_to($tmpfilepath);
|
|
||||||
|
|
||||||
if ($mode === 'tinyicon') {
|
if ($mode === 'tinyicon') {
|
||||||
$data = generate_image_thumbnail($tmpfilepath, 24, 24);
|
$data = $file->generate_image_thumbnail(24, 24);
|
||||||
|
|
||||||
} else if ($mode === 'thumb') {
|
} else if ($mode === 'thumb') {
|
||||||
$data = generate_image_thumbnail($tmpfilepath, 90, 90);
|
$data = $file->generate_image_thumbnail(90, 90);
|
||||||
|
|
||||||
} else if ($mode === 'bigthumb') {
|
} else if ($mode === 'bigthumb') {
|
||||||
$data = generate_image_thumbnail($tmpfilepath, 250, 250);
|
$data = $file->generate_image_thumbnail(250, 250);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new file_exception('storedfileproblem', 'Invalid preview mode requested');
|
throw new file_exception('storedfileproblem', 'Invalid preview mode requested');
|
||||||
}
|
}
|
||||||
|
|
||||||
unlink($tmpfilepath);
|
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -290,11 +290,7 @@ function label_generate_resized_image(stored_file $file, $maxwidth, $maxheight)
|
||||||
$mimetype = $file->get_mimetype();
|
$mimetype = $file->get_mimetype();
|
||||||
if ($mimetype === 'image/gif' or $mimetype === 'image/jpeg' or $mimetype === 'image/png') {
|
if ($mimetype === 'image/gif' or $mimetype === 'image/jpeg' or $mimetype === 'image/png') {
|
||||||
require_once($CFG->libdir.'/gdlib.php');
|
require_once($CFG->libdir.'/gdlib.php');
|
||||||
$tmproot = make_temp_directory('mod_label');
|
$data = $file->generate_image_thumbnail($width, $height);
|
||||||
$tmpfilepath = $tmproot.'/'.$file->get_contenthash();
|
|
||||||
$file->copy_content_to($tmpfilepath);
|
|
||||||
$data = generate_image_thumbnail($tmpfilepath, $width, $height);
|
|
||||||
unlink($tmpfilepath);
|
|
||||||
|
|
||||||
if (!empty($data)) {
|
if (!empty($data)) {
|
||||||
$fs = get_file_storage();
|
$fs = get_file_storage();
|
||||||
|
|
|
@ -486,7 +486,6 @@ class repository_filesystem extends repository {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$filename = sha1($filecontents);
|
$filename = sha1($filecontents);
|
||||||
unset($filecontents);
|
|
||||||
|
|
||||||
// Try to get generated thumbnail for this file.
|
// Try to get generated thumbnail for this file.
|
||||||
$fs = get_file_storage();
|
$fs = get_file_storage();
|
||||||
|
@ -499,7 +498,7 @@ class repository_filesystem extends repository {
|
||||||
} else {
|
} else {
|
||||||
$size = 24;
|
$size = 24;
|
||||||
}
|
}
|
||||||
if (!$data = @generate_image_thumbnail($origfile, $size, $size)) {
|
if (!$data = generate_image_thumbnail_from_string($filecontents, $size, $size)) {
|
||||||
// Generation failed.
|
// Generation failed.
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue