mirror of
https://github.com/moodle/moodle.git
synced 2025-04-19 07:25:30 +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
@ -384,25 +384,19 @@ class file_storage {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir.'/gdlib.php');
|
||||
|
||||
$tmproot = make_temp_directory('thumbnails');
|
||||
$tmpfilepath = $tmproot.'/'.$file->get_contenthash();
|
||||
$file->copy_content_to($tmpfilepath);
|
||||
|
||||
if ($mode === 'tinyicon') {
|
||||
$data = generate_image_thumbnail($tmpfilepath, 24, 24);
|
||||
$data = $file->generate_image_thumbnail(24, 24);
|
||||
|
||||
} else if ($mode === 'thumb') {
|
||||
$data = generate_image_thumbnail($tmpfilepath, 90, 90);
|
||||
$data = $file->generate_image_thumbnail(90, 90);
|
||||
|
||||
} else if ($mode === 'bigthumb') {
|
||||
$data = generate_image_thumbnail($tmpfilepath, 250, 250);
|
||||
$data = $file->generate_image_thumbnail(250, 250);
|
||||
|
||||
} else {
|
||||
throw new file_exception('storedfileproblem', 'Invalid preview mode requested');
|
||||
}
|
||||
|
||||
unlink($tmpfilepath);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
@ -290,11 +290,7 @@ function label_generate_resized_image(stored_file $file, $maxwidth, $maxheight)
|
||||
$mimetype = $file->get_mimetype();
|
||||
if ($mimetype === 'image/gif' or $mimetype === 'image/jpeg' or $mimetype === 'image/png') {
|
||||
require_once($CFG->libdir.'/gdlib.php');
|
||||
$tmproot = make_temp_directory('mod_label');
|
||||
$tmpfilepath = $tmproot.'/'.$file->get_contenthash();
|
||||
$file->copy_content_to($tmpfilepath);
|
||||
$data = generate_image_thumbnail($tmpfilepath, $width, $height);
|
||||
unlink($tmpfilepath);
|
||||
$data = $file->generate_image_thumbnail($width, $height);
|
||||
|
||||
if (!empty($data)) {
|
||||
$fs = get_file_storage();
|
||||
|
@ -486,7 +486,6 @@ class repository_filesystem extends repository {
|
||||
return null;
|
||||
}
|
||||
$filename = sha1($filecontents);
|
||||
unset($filecontents);
|
||||
|
||||
// Try to get generated thumbnail for this file.
|
||||
$fs = get_file_storage();
|
||||
@ -499,7 +498,7 @@ class repository_filesystem extends repository {
|
||||
} else {
|
||||
$size = 24;
|
||||
}
|
||||
if (!$data = @generate_image_thumbnail($origfile, $size, $size)) {
|
||||
if (!$data = generate_image_thumbnail_from_string($filecontents, $size, $size)) {
|
||||
// Generation failed.
|
||||
return null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user