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


PHP stored_file::get_imageinfo方法代码示例

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


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

示例1: resize

 /**
  * Shame that this was nicked from gdlib.php and that there isn't a function I could have used from there.
  * Creates a resized version of image and stores copy in file area
  *
  * @param context $context
  * @param string $component
  * @param string filearea
  * @param int $itemid
  * @param stored_file $originalfile
  * @param int $newwidth;
  * @param int $newheight;
  * @return stored_file
  */
 public static function resize(\stored_file $originalfile, $resizefilename = false, $newwidth = false, $newheight = false, $jpgquality = 90)
 {
     if ($resizefilename === false) {
         $resizefilename = $originalfile->get_filename();
     }
     if (!$newwidth && !$newheight) {
         return false;
     }
     $contextid = $originalfile->get_contextid();
     $component = $originalfile->get_component();
     $filearea = $originalfile->get_filearea();
     $itemid = $originalfile->get_itemid();
     $imageinfo = (object) $originalfile->get_imageinfo();
     $imagefnc = '';
     if (empty($imageinfo)) {
         return false;
     }
     // Create temporary image for processing.
     $tmpimage = tempnam(sys_get_temp_dir(), 'tmpimg');
     \file_put_contents($tmpimage, $originalfile->get_content());
     if (!$newheight) {
         $m = $imageinfo->height / $imageinfo->width;
         // Multiplier to work out $newheight.
         $newheight = $newwidth * $m;
     } else {
         if (!$newwidth) {
             $m = $imageinfo->width / $imageinfo->height;
             // Multiplier to work out $newwidth.
             $newwidth = $newheight * $m;
         }
     }
     $t = null;
     switch ($imageinfo->mimetype) {
         case 'image/gif':
             if (\function_exists('imagecreatefromgif')) {
                 $im = \imagecreatefromgif($tmpimage);
             } else {
                 \debugging('GIF not supported on this server');
                 unlink($tmpimage);
                 return false;
             }
             // Guess transparent colour from GIF.
             $transparent = \imagecolortransparent($im);
             if ($transparent != -1) {
                 $t = \imagecolorsforindex($im, $transparent);
             }
             break;
         case 'image/jpeg':
             if (\function_exists('imagecreatefromjpeg')) {
                 $im = \imagecreatefromjpeg($tmpimage);
             } else {
                 \debugging('JPEG not supported on this server');
                 unlink($tmpimage);
                 return false;
             }
             // If the user uploads a jpeg them we should process as a jpeg if possible.
             if (\function_exists('imagejpeg')) {
                 $imagefnc = 'imagejpeg';
                 $filters = null;
                 // Not used.
                 $quality = $jpgquality;
             } else {
                 if (\function_exists('imagepng')) {
                     $imagefnc = 'imagepng';
                     $filters = PNG_NO_FILTER;
                     $quality = 1;
                 } else {
                     \debugging('Jpeg and png not supported on this server, please fix server configuration');
                     unlink($tmpimage);
                     return false;
                 }
             }
             break;
         case 'image/png':
             if (\function_exists('imagecreatefrompng')) {
                 $im = \imagecreatefrompng($tmpimage);
             } else {
                 \debugging('PNG not supported on this server');
                 unlink($tmpimage);
                 return false;
             }
             break;
         default:
             unlink($tmpimage);
             return false;
     }
     unlink($tmpimage);
//.........这里部分代码省略.........
开发者ID:pramithkm,项目名称:moodle-theme_snap,代码行数:101,代码来源:image.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';
                $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);
                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:sumitnegi933,项目名称:Moodle_lms_New,代码行数:58,代码来源:lib.php

示例3: get_image_details

 /**
  * Get the image details from a file and return them.
  * @param stored_file $file
  * @param $pagecount
  * @return mixed array|false
  */
 protected static function get_image_details($file, $pagecount)
 {
     if ($imageinfo = $file->get_imageinfo()) {
         $imgurl = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
         // Prevent browser from caching image if it has changed.
         $imgurl->param('ts', $file->get_timemodified());
         return array($imgurl, $imageinfo['width'], $imageinfo['height'], $pagecount);
     }
     // Something went wrong.
     return false;
 }
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:17,代码来源:locallib.php


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