当前位置: 首页>>代码示例>>PHP>>正文


PHP stored_file::generate_image_thumbnail方法代码示例

本文整理汇总了PHP中stored_file::generate_image_thumbnail方法的典型用法代码示例。如果您正苦于以下问题:PHP stored_file::generate_image_thumbnail方法的具体用法?PHP stored_file::generate_image_thumbnail怎么用?PHP stored_file::generate_image_thumbnail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stored_file的用法示例。


在下文中一共展示了stored_file::generate_image_thumbnail方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: create_imagefile_preview

 /**
  * Generates a preview for the stored image file
  *
  * @param stored_file $file the image we want to preview
  * @param string $mode preview mode, eg. 'thumb'
  * @return string|bool false if a problem occurs, the thumbnail image data otherwise
  */
 protected function create_imagefile_preview(stored_file $file, $mode)
 {
     global $CFG;
     require_once $CFG->libdir . '/gdlib.php';
     if ($mode === 'tinyicon') {
         $data = $file->generate_image_thumbnail(24, 24);
     } else {
         if ($mode === 'thumb') {
             $data = $file->generate_image_thumbnail(90, 90);
         } else {
             if ($mode === 'bigthumb') {
                 $data = $file->generate_image_thumbnail(250, 250);
             } else {
                 throw new file_exception('storedfileproblem', 'Invalid preview mode requested');
             }
         }
     }
     return $data;
 }
开发者ID:IFPBMoodle,项目名称:moodle,代码行数:26,代码来源:file_storage.php

示例2: label_generate_resized_image

/**
 * Resize the image, if required, then generate an img tag and, if required, a link to the full-size image
 * @param stored_file $file the image file to process
 * @param int $maxwidth the maximum width allowed for the image
 * @param int $maxheight the maximum height allowed for the image
 * @return string HTML fragment to add to the label
 */
function label_generate_resized_image(stored_file $file, $maxwidth, $maxheight)
{
    global $CFG;
    $fullurl = moodle_url::make_draftfile_url($file->get_itemid(), $file->get_filepath(), $file->get_filename());
    $link = null;
    $attrib = array('alt' => $file->get_filename(), 'src' => $fullurl);
    if ($imginfo = $file->get_imageinfo()) {
        // Work out the new width / height, bounded by maxwidth / maxheight
        $width = $imginfo['width'];
        $height = $imginfo['height'];
        if (!empty($maxwidth) && $width > $maxwidth) {
            $height *= (double) $maxwidth / $width;
            $width = $maxwidth;
        }
        if (!empty($maxheight) && $height > $maxheight) {
            $width *= (double) $maxheight / $height;
            $height = $maxheight;
        }
        $attrib['width'] = $width;
        $attrib['height'] = $height;
        // If the size has changed and the image is of a suitable mime type, generate a smaller version
        if ($width != $imginfo['width']) {
            $mimetype = $file->get_mimetype();
            if ($mimetype === 'image/gif' or $mimetype === 'image/jpeg' or $mimetype === 'image/png') {
                require_once $CFG->libdir . '/gdlib.php';
                $data = $file->generate_image_thumbnail($width, $height);
                if (!empty($data)) {
                    $fs = get_file_storage();
                    $record = array('contextid' => $file->get_contextid(), 'component' => $file->get_component(), 'filearea' => $file->get_filearea(), 'itemid' => $file->get_itemid(), 'filepath' => '/', 'filename' => 's_' . $file->get_filename());
                    $smallfile = $fs->create_file_from_string($record, $data);
                    // Replace the image 'src' with the resized file and link to the original
                    $attrib['src'] = moodle_url::make_draftfile_url($smallfile->get_itemid(), $smallfile->get_filepath(), $smallfile->get_filename());
                    $link = $fullurl;
                }
            }
        }
    } else {
        // Assume this is an image type that get_imageinfo cannot handle (e.g. SVG)
        $attrib['width'] = $maxwidth;
    }
    $img = html_writer::empty_tag('img', $attrib);
    if ($link) {
        return html_writer::link($link, $img);
    } else {
        return $img;
    }
}
开发者ID:dg711,项目名称:moodle,代码行数:54,代码来源:lib.php


注:本文中的stored_file::generate_image_thumbnail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。