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


PHP Image::getWidth方法代码示例

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


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

示例1: readFolder

 public function readFolder()
 {
     $folder = $this->customer->getFolderName();
     $dir = DIR_IMAGE . "catalog/" . $folder;
     $allfiles = scandir($dir);
     $img_links = array();
     $counting = 0;
     foreach ($allfiles as $image) {
         //if the file is not hidden get the the URI
         if (substr($image, 0, 1) != '.') {
             //Once we get certified the config.php needs to be modified.
             $modify_image = new Image(DIR_IMAGE . "catalog/" . $folder . "/" . $image);
             // $mark = new Image(DIR_IMAGE. "logo.png");
             $width = $modify_image->getWidth() * 0.2;
             $height = $modify_image->getHeight() * 0.2;
             // $mark->resize($width, $height);
             // $modify_image->watermark($mark);
             $size = $width * $height;
             $modify_image->save($modify_image->getFile());
             $img_links[$counting]['source'] = HTTPS_SERVER . "/image/catalog/" . $folder . "/" . $image;
             $img_links[$counting]['width'] = $modify_image->getWidth();
             $img_links[$counting]['height'] = $modify_image->getHeight();
             $counting++;
         }
     }
     return $img_links;
 }
开发者ID:hutdast,项目名称:rip,代码行数:27,代码来源:account.php

示例2: addTag

 function addTag($srcPath, $dstPath)
 {
     $srcImage = new Image($srcPath);
     $tagImagePath = CODE_ROOT_DIR . "uploads/custom/" . Config::get("watermarkImageSrc");
     if (!file_exists($tagImagePath)) {
         return;
     }
     $tagImage = new Image($tagImagePath);
     list($posV, $posH) = explode(",", Config::get("imageWatermarkPosition"));
     $tagMarginH = 5;
     $tagMarginV = 5;
     if ($posH == "l") {
         $tagPositionX = 0 + $tagMarginH;
     } else {
         $tagPositionX = max($srcImage->getWidth() - $tagImage->getWidth() - $tagMarginH, 0);
     }
     if ($posV == "t") {
         $tagPositionY = 0 + $tagMarginV;
     } else {
         $tagPositionY = max($srcImage->getHeight() - $tagImage->getHeight() - $tagMarginV, 0);
     }
     imagecopyresampled($srcImage->im, $tagImage->im, $tagPositionX, $tagPositionY, 0, 0, $tagImage->getWidth(), $tagImage->getHeight(), $tagImage->getWidth(), $tagImage->getHeight());
     $srcImage->setPath($dstPath);
     $srcImage->saveToFile();
 }
开发者ID:reinfire,项目名称:arfooo,代码行数:25,代码来源:ImageResizer.php

示例3: imageResize

		static public function imageResize($fname,$width,$height) {
			$i = new Image( $fname );
			$owhr=$i->getWidth()/$i->getHeight();
			$twhr=$width/$height;
			if( $owhr==$twhr )	{
				$i->resize( $width,$height );
			}	elseif( $owhr>$twhr )	{
				$i->resizeToHeight( $height );
				$i->crop( ($i->getWidth()-$width)/2, 0, $width, $height);
			}	else	{
				$i->resizeToWidth( $width );
				$i->crop( 0, ($i->getHeight()-$height)/2, $width, $height);
			}
			$i->save();
		}
开发者ID:AuTiMoThY,项目名称:Dfocus-concord-php,代码行数:15,代码来源:JWStdio.inc.php

示例4: resize

 /**
  * @param string $filename
  * @param int $width
  * @param int $height
  * @return string
  */
 public function resize($filename, $width, $height)
 {
     if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) {
         return null;
     }
     $info = pathinfo($filename);
     $extension = $info['extension'];
     $old_image = $filename;
     try {
         $image = new Image(DIR_IMAGE . $old_image);
     } catch (Exception $exc) {
         $image = new Image(DIR_IMAGE . 'no_image.jpg');
     }
     /// Ensure target size doesn't exceed original size
     $ratio = $image->getWidth() / $image->getHeight();
     $expectedHeight = round($width / $ratio);
     $expectedWidth = round($height * $ratio);
     if ($image->getWidth() >= $width) {
         $targetWidth = $width;
         $targetHeight = $expectedHeight;
     } else {
         $targetWidth = $image->getWidth();
         $targetHeight = $image->getHeight();
     }
     if ($image->getHeight() < $targetHeight) {
         $targetWidth = $expectedWidth;
         $targetHeight = $image->getHeight();
     }
     $new_image = 'cache/' . substr($filename, 0, strrpos($filename, '.')) . '-' . $targetWidth . 'x' . $targetHeight . '.' . $extension;
     if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) {
         $path = '';
         $directories = explode('/', dirname(str_replace('../', '', $new_image)));
         foreach ($directories as $directory) {
             $path = $path . '/' . $directory;
             if (!file_exists(DIR_IMAGE . $path)) {
                 @mkdir(DIR_IMAGE . $path, 0777);
             }
         }
         $image->resize($targetWidth, $targetHeight);
         $image->save(DIR_IMAGE . $new_image);
     }
     if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) {
         return HTTPS_IMAGE . $new_image;
     } else {
         return HTTP_IMAGE . $new_image;
     }
 }
开发者ID:ralfeus,项目名称:moomi-daeri.com,代码行数:53,代码来源:image.php

示例5: setProperties

 /**
  * Sets the objects properties
  *
  * @param $percentage float The percentage that the merge image should take up.
  */
 protected function setProperties($percentage)
 {
     if ($percentage > 1) {
         throw new \InvalidArgumentException('$percentage must be less than 1');
     }
     $this->sourceImageHeight = $this->sourceImage->getHeight();
     $this->sourceImageWidth = $this->sourceImage->getWidth();
     $this->mergeImageHeight = $this->mergeImage->getHeight();
     $this->mergeImageWidth = $this->mergeImage->getWidth();
     $this->calculateOverlap($percentage);
     $this->calculateCenter();
 }
开发者ID:summer11123,项目名称:simple-qrcode,代码行数:17,代码来源:ImageMerge.php

示例6: setProperties

 /**
  * Sets the objects properties
  *
  * @param $percentage float The percentage that the merge image should take up.
  */
 protected function setProperties($percentage)
 {
     if ($percentage > 1) {
         throw new \InvalidArgumentException('$percentage must be less than 1');
     }
     $this->sourceHeight = $this->sourceImage->getHeight();
     $this->sourceWidth = $this->sourceImage->getWidth();
     $this->mergeHeight = $this->mergeImage->getHeight();
     $this->mergeWidth = $this->mergeImage->getWidth();
     $this->postMergeHeight = $this->mergeHeight * $percentage;
     $this->postMergeWidth = $this->mergeWidth * $percentage;
     $this->mergePosHeight = $this->sourceHeight / 2 - $this->postMergeHeight / 2;
     $this->mergePosWidth = $this->sourceWidth / 2 - $this->postMergeHeight / 2;
 }
开发者ID:hechunwen,项目名称:simple-qrcode,代码行数:19,代码来源:ImageMerge.php

示例7: iframe_add

    /**
     * Add a post
     */
    public function iframe_add()
    {
        $this->setView('iframe_add.php');
        @set_time_limit(0);
        $uploaded_files = array();
        try {
            if (!isset(User_Model::$auth_data)) {
                throw new Exception(__('POST_ADD_ERROR_SESSION_EXPIRED'));
            }
            $is_student = isset(User_Model::$auth_data['student_number']);
            // Message
            $message = isset($_POST['message']) ? trim($_POST['message']) : '';
            if ($message == '' || $message == __('PUBLISH_DEFAULT_MESSAGE')) {
                throw new Exception(__('POST_ADD_ERROR_NO_MESSAGE'));
            }
            $message = preg_replace('#\\n{2,}#', "\n\n", $message);
            // Category
            if (!isset($_POST['category']) || !ctype_digit($_POST['category'])) {
                throw new Exception(__('POST_ADD_ERROR_NO_CATEGORY'));
            }
            $category = (int) $_POST['category'];
            // Official post (in a group)
            $official = isset($_POST['official']);
            // Group
            $group = isset($_POST['group']) && ctype_digit($_POST['group']) ? (int) $_POST['group'] : 0;
            if ($group == 0) {
                $group = null;
                $official = false;
            } else {
                $groups_auth = Group_Model::getAuth();
                if (isset($groups_auth[$group])) {
                    if ($official && !$groups_auth[$group]['admin']) {
                        throw new Exception(__('POST_ADD_ERROR_OFFICIAL'));
                    }
                } else {
                    throw new Exception(__('POST_ADD_ERROR_GROUP_NOT_FOUND'));
                }
            }
            // Private message
            $private = isset($_POST['private']);
            if ($private && !$is_student) {
                throw new Exception(__('POST_ADD_ERROR_PRIVATE'));
            }
            $attachments = array();
            // Photos
            if (isset($_FILES['attachment_photo']) && is_array($_FILES['attachment_photo']['name'])) {
                foreach ($_FILES['attachment_photo']['size'] as $size) {
                    if ($size > Config::UPLOAD_MAX_SIZE_PHOTO) {
                        throw new Exception(__('POST_ADD_ERROR_PHOTO_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_PHOTO))));
                    }
                }
                if ($filepaths = File::upload('attachment_photo')) {
                    foreach ($filepaths as $filepath) {
                        $uploaded_files[] = $filepath;
                    }
                    foreach ($filepaths as $i => $filepath) {
                        $name = isset($_FILES['attachment_photo']['name'][$i]) ? $_FILES['attachment_photo']['name'][$i] : '';
                        try {
                            $img = new Image();
                            $img->load($filepath);
                            $type = $img->getType();
                            if ($type == IMAGETYPE_JPEG) {
                                $ext = 'jpg';
                            } else {
                                if ($type == IMAGETYPE_GIF) {
                                    $ext = 'gif';
                                } else {
                                    if ($type == IMAGETYPE_PNG) {
                                        $ext = 'png';
                                    } else {
                                        throw new Exception();
                                    }
                                }
                            }
                            if ($img->getWidth() > 800) {
                                $img->setWidth(800, true);
                            }
                            $img->save($filepath);
                            // Thumb
                            $thumbpath = $filepath . '.thumb';
                            $img->thumb(Config::$THUMBS_SIZES[0], Config::$THUMBS_SIZES[1]);
                            $img->setType(IMAGETYPE_JPEG);
                            $img->save($thumbpath);
                            unset($img);
                            $attachments[] = array($filepath, $name, $thumbpath);
                            $uploaded_files[] = $thumbpath;
                        } catch (Exception $e) {
                            throw new Exception(__('POST_ADD_ERROR_PHOTO_FORMAT'));
                        }
                    }
                }
            }
            // Vidéos
            /* @uses PHPVideoToolkit : http://code.google.com/p/phpvideotoolkit/
             * @requires ffmpeg, php5-ffmpeg
             */
            if (isset($_FILES['attachment_video']) && is_array($_FILES['attachment_video']['name'])) {
//.........这里部分代码省略.........
开发者ID:Godefroy,项目名称:iseplive,代码行数:101,代码来源:Post.php

示例8: buildImage

 /**
  * Create a new image based on an image preset.
  *
  * @param array $actions An image preset array.
  * @param Image $image Path of the source file.
  * @param string $dst Path of the destination file.
  * @throws \RuntimeException
  * @return Image
  */
 protected function buildImage($actions, Image $image, $dst)
 {
     foreach ($actions as $action) {
         // Make sure the width and height are computed first so they can be used
         // in relative x/yoffsets like 'center' or 'bottom'.
         if (isset($action['width'])) {
             $action['width'] = $this->percent($action['width'], $image->getWidth());
         }
         if (isset($action['height'])) {
             $action['height'] = $this->percent($action['height'], $image->getHeight());
         }
         if (isset($action['xoffset'])) {
             $action['xoffset'] = $this->keywords($action['xoffset'], $image->getWidth(), $action['width']);
         }
         if (isset($action['yoffset'])) {
             $action['yoffset'] = $this->keywords($action['yoffset'], $image->getHeight(), $action['height']);
         }
         $this->getMethodCaller()->call($image, $action['action'], $action);
     }
     return $image->save($dst);
 }
开发者ID:onigoetz,项目名称:imagecache,代码行数:30,代码来源:Manager.php

示例9: alphaMask

 public function alphaMask(Image $mask)
 {
     $new_img = $this->newImage($this->getWidth(), $this->getHeight());
     // resize the mask if it's not the same size
     if ($mask->getWidth() != $this->getWidth() || $mask->getHeight() != $this->getHeight()) {
         $mask->resize($this->getWidth(), $this->getHeight(), self::RESIZE_BASE_MIN, true);
     }
     // put the mask on
     for ($x = 0; $x < $this->getWidth(); $x++) {
         for ($y = 0; $y < $this->getHeight(); $y++) {
             $alpha = imagecolorsforindex($mask->getHandle(), imagecolorat($mask->getHandle(), $x, $y));
             $alpha = 127 - floor($alpha['red'] / 2);
             $color = imagecolorsforindex($this->getHandle(), imagecolorat($this->getHandle(), $x, $y));
             $new_color = imagecolorallocatealpha($new_img, $color['red'], $color['green'], $color['blue'], $alpha);
             imagesetpixel($new_img, $x, $y, $new_color);
         }
     }
     imagecopy($this->getHandle(), $new_img, 0, 0, 0, 0, $this->getWidth(), $this->getHeight());
     imagedestroy($new_img);
 }
开发者ID:nicksp,项目名称:BakedCarrot,代码行数:20,代码来源:Image.php

示例10: handlePluginList

 private function handlePluginList($tag, $parameters)
 {
     $template = new TemplateEngine($this->getPath() . "templates/" . $this->templateFile);
     $request = Request::getInstance();
     $view = ViewManager::getInstance();
     $searchcriteria = isset($parameters) && array_key_exists('searchcriteria', $parameters) ? $parameters['searchcriteria'] : array();
     $keys = isset($parameters) && array_key_exists('keys', $parameters) ? $parameters['keys'] : array();
     $searchcriteria['id'] = $keys;
     $settings = $this->plugin->getSettings();
     $template->setVariable('settings', $settings);
     $systemSite = new SystemSite();
     $tree = $systemSite->getTree();
     $list = $this->getList($searchcriteria, $pagesize, $page);
     foreach ($list['data'] as &$item) {
         //TODO get url from caller plugin (newsletter) to track visits
         $url = new Url();
         $url->setPath($request->getProtocol() . $request->getDomain() . $tree->getPath($item['tree_id']));
         $url->setParameter('id', $item['id']);
         $url->setParameter(ViewManager::URL_KEY_DEFAULT, Calendar::VIEW_DETAIL);
         $item['href_detail'] = $url->getUrl(true);
         if ($item['thumbnail']) {
             $img = new Image($item['thumbnail'], $this->plugin->getContentPath(true));
             $item['thumbnail'] = array('src' => $this->plugin->getContentPath(false) . $img->getFileName(false), 'width' => $img->getWidth(), 'height' => $img->getHeight());
         }
     }
     $template->setVariable('calendar', $list);
     $this->template[$tag] = $template;
 }
开发者ID:rverbrugge,项目名称:dif,代码行数:28,代码来源:CalendarOverview.php

示例11: handleOverview

 /**
  * handle overview request
  */
 private function handleOverview()
 {
     $request = Request::getInstance();
     $view = ViewManager::getInstance();
     $page = $this->getPage();
     $this->pagerUrl->setParameter($view->getUrlId(), $view->getType());
     $taglist = $this->plugin->getTagList(array('plugin_type' => News::TYPE_ARCHIVE));
     if (!$taglist) {
         return;
     }
     $tree = $this->director->tree;
     $url = new Url(true);
     $url->setParameter($view->getUrlId(), News::VIEW_DETAIL);
     // link to news tree nodes
     $treeRef = new NewsTreeRef();
     foreach ($taglist as $item) {
         $template = new TemplateEngine($this->getPath() . "templates/" . $this->templateFile);
         $template->setPostfix($item['tag']);
         $template->setCacheable(true);
         // check if template is in cache
         if (!$template->isCached()) {
             // get settings
             $settings = $this->getSettings();
             $key = array('tree_id' => $item['tree_id'], 'tag' => $item['tag']);
             $detail = $this->getDetail($key);
             $treeRefList = $treeRef->getList($key);
             $treeItemList = array();
             foreach ($treeRefList['data'] as $treeRefItem) {
                 if (!$tree->exists($treeRefItem['ref_tree_id'])) {
                     continue;
                 }
                 $treeItemList[] = $treeRefItem['ref_tree_id'];
             }
             if (!$treeItemList) {
                 continue;
             }
             $searchcriteria = array('tree_id' => $treeItemList, 'active' => true);
             if ($detail['online']) {
                 $searchcriteria['archiveonline'] = $detail['online'];
             }
             $searchcriteria['archiveoffline'] = $detail['offline'] ? $detail['offline'] : time();
             $overview = $this->getNewsOverview();
             $list = $overview->getList($searchcriteria, $settings['rows'], $page);
             foreach ($list['data'] as &$newsitem) {
                 $url->setParameter('id', $newsitem['id']);
                 $newsitem['href_detail'] = $url->getUrl(true);
                 if ($newsitem['thumbnail']) {
                     $img = new Image($newsitem['thumbnail'], $this->plugin->getContentPath(true));
                     $newsitem['thumbnail'] = array('src' => $this->plugin->getContentPath(false) . $img->getFileName(false), 'width' => $img->getWidth(), 'height' => $img->getHeight());
                 }
             }
             $template->setVariable('news', $list);
             $template->setVariable('display', $settings['display'], false);
         }
         $this->template[$item['tag']] = $template;
     }
 }
开发者ID:rverbrugge,项目名称:dif,代码行数:60,代码来源:NewsArchive.php

示例12: Image

for ($i = 0, $icount = count($_JPOST->images); $i < $icount; $i++) {
    # Storing our image
    $img_details = $_JPOST->images[$i];
    # Getting our image
    $tmpimg = new Image();
    $tmpimg->load($img_details->src);
    # Our dimentions
    $x = (int) $img_details->x;
    $y = (int) $img_details->y;
    $width = (int) $img_details->width;
    $height = (int) $img_details->height;
    $rotate = (double) $img_details->rotate;
    switch ($img_details->size) {
        case 'contain':
            # Calaulating our actual widths/heights
            $px = $width / $tmpimg->getWidth();
            $py = $height / $tmpimg->getHeight();
            # Getting our percentages
            if ($px >= $py) {
                $py /= $px;
                $px = 1.0;
            } else {
                $px /= $py;
                $py = 1.0;
            }
            # Calculating our new positions
            $x += ($width - $width * $py) * 0.5;
            $y += ($height - $height * $px) * 0.5;
            $width = $width * $py;
            $height = $height * $px;
            break;
开发者ID:nuQuery,项目名称:v1m0-api-image,代码行数:31,代码来源:collage.php

示例13: handleTreeEditGet

 /**
  * handle tree edit
  */
 private function handleTreeEditGet($retrieveFields = true)
 {
     $template = new TemplateEngine($this->getPath() . "templates/" . $this->templateFile);
     $request = Request::getInstance();
     $view = ViewManager::getInstance();
     $view->setType(ViewManager::TREE_EDIT);
     if (!$request->exists('id')) {
         throw new Exception('Link is missing.');
     }
     $id = intval($request->getValue('id'));
     $template->setVariable('id', $id, false);
     $key = array('id' => $id);
     if ($retrieveFields) {
         $fields = $this->getDetail($key);
     } else {
         $fields = $this->getFields(SqlParser::MOD_UPDATE);
         $detail = $this->getDetail($key);
         $fields['image'] = $detail['image'];
     }
     $this->setFields($fields);
     if ($fields['image']) {
         $img = new Image($fields['image'], $this->getContentPath(true));
         $fields['image'] = array('src' => $this->getContentPath(false) . $img->getFileName(false), 'width' => $img->getWidth(), 'height' => $img->getHeight());
     }
     $template->setVariable($fields, NULL, false);
     $this->handleTreeSettings($template);
     $template->setVariable('fckBox', $this->getEditor($fields['text']), false);
     // get all tree nodes which have plugin modules
     $site = new SystemSite();
     $tree = $site->getTree();
     $treelist = $tree->getList();
     foreach ($treelist as &$item) {
         $item['name'] = $tree->toString($item['id'], '/', 'name');
     }
     $template->setVariable('cbo_tree_id', Utils::getHtmlCombo($treelist, $fields['ref_tree_id'], '...'));
     // get crop settings
     $settings = $this->plugin->getObject(Links::TYPE_SETTINGS)->getSettings($fields['tag'], $fields['tree_id']);
     //only crop if both width and height defaults are set
     if ($fields['image'] && $settings['image_width'] && $settings['image_height'] && ($fields['image']['width'] > $settings['image_width'] || $fields['image']['height'] > $settings['image_height'])) {
         $theme = $this->director->theme;
         $parseFile = new ParseFile();
         $parseFile->setVariable($fields, NULL, false);
         $parseFile->setVariable('imgTag', 'imgsrc', false);
         $parseFile->setVariable($settings, NULL, false);
         $parseFile->setSource($this->getHtdocsPath(true) . "js/cropinit.js.in");
         //$parseFile->setDestination($this->getCachePath(true)."cropinit_tpl_content.js");
         //$parseFile->save();
         $theme->addJavascript($parseFile->fetch());
         //$this->headers[] = '<script type="text/javascript" src="'.$this->getCachePath().'cropinit_tpl_content.js"></script>';
         $theme->addHeader('<script type="text/javascript" src="' . DIF_VIRTUAL_WEB_ROOT . 'js/prototype.js"></script>');
         $theme->addHeader('<script type="text/javascript" src="' . DIF_VIRTUAL_WEB_ROOT . 'js/scriptaculous.js"></script>');
         $theme->addHeader('<script type="text/javascript" src="' . DIF_VIRTUAL_WEB_ROOT . 'js/cropper.js"></script>');
         $theme->addHeader('<script type="text/javascript" src="' . DIF_VIRTUAL_WEB_ROOT . 'js/mint.js"></script>');
     }
     $this->template[$this->director->theme->getConfig()->main_tag] = $template;
 }
开发者ID:rverbrugge,项目名称:dif,代码行数:59,代码来源:LinksOverview.php

示例14: tag

 public function tag(Image $img)
 {
     return "<img src = \"{$img->getPath()}\" alt=\"\" width=\"{$img->getWidth()}\" height=\"{$img->getHeight()}\" />";
 }
开发者ID:adollar,项目名称:patterns,代码行数:4,代码来源:proxy.php

示例15: add

 /**
  * Add a group
  */
 public function add($params)
 {
     $this->setView('add.php');
     $this->setTitle(__('GROUP_ADD_TITLE'));
     $is_logged = isset(User_Model::$auth_data);
     $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1';
     // Authorization
     if (!$is_admin) {
         throw new ActionException('Page', 'error404');
     }
     $group = array();
     // Saving data
     if (isset($_POST['name']) && isset($_POST['creation_date']) && isset($_POST['mail']) && isset($_POST['description'])) {
         $uploaded_files = array();
         try {
             // Members
             $members = array();
             if (isset($_POST['members_ids']) && is_array($_POST['members_ids'])) {
                 foreach ($_POST['members_ids'] as $id) {
                     if (ctype_digit($id)) {
                         $id = (int) $id;
                         $members[$id] = array('title' => isset($_POST['member_title_' . $id]) ? $_POST['member_title_' . $id] : '', 'admin' => isset($_POST['member_admin_' . $id]));
                     }
                 }
             }
             // Other info
             $data = array('name' => $_POST['name'], 'creation_date' => $_POST['creation_date'], 'mail' => $_POST['mail'], 'description' => $_POST['description'], 'members' => $members);
             // Avatar
             if (isset($_FILES['avatar']) && !is_array($_FILES['avatar']['name'])) {
                 if ($_FILES['avatar']['size'] > Config::UPLOAD_MAX_SIZE_PHOTO) {
                     throw new FormException('avatar');
                 }
                 if ($avatarpath = File::upload('avatar')) {
                     $uploaded_files[] = $avatarpath;
                     try {
                         $img = new Image();
                         $img->load($avatarpath);
                         $type = $img->getType();
                         if ($type == IMAGETYPE_JPEG) {
                             $ext = 'jpg';
                         } else {
                             if ($type == IMAGETYPE_GIF) {
                                 $ext = 'gif';
                             } else {
                                 if ($type == IMAGETYPE_PNG) {
                                     $ext = 'png';
                                 } else {
                                     throw new Exception();
                                 }
                             }
                         }
                         if ($img->getWidth() > 800) {
                             $img->setWidth(800, true);
                         }
                         $img->setType(IMAGETYPE_JPEG);
                         $img->save($avatarpath);
                         // Thumb
                         $avatarthumbpath = $avatarpath . '.thumb';
                         $img->thumb(Config::$AVATARS_THUMBS_SIZES[0], Config::$AVATARS_THUMBS_SIZES[1]);
                         $img->setType(IMAGETYPE_JPEG);
                         $img->save($avatarthumbpath);
                         unset($img);
                         $uploaded_files[] = $avatarthumbpath;
                         $data['avatar_path'] = $avatarthumbpath;
                         $data['avatar_big_path'] = $avatarpath;
                     } catch (Exception $e) {
                         throw new FormException('avatar');
                     }
                 }
             }
             $url_name = $this->model->create($data);
             Routes::redirect('group', array('group' => $url_name));
         } catch (FormException $e) {
             foreach ($uploaded_files as $uploaded_file) {
                 File::delete($uploaded_file);
             }
             foreach ($data as $key => $value) {
                 $group[$key] = $value;
             }
             $group['members'] = Student_Model::getInfoByUsersIds(array_keys($members));
             foreach ($group['members'] as &$member) {
                 if (isset($members[(int) $member['user_id']])) {
                     $member['title'] = $members[(int) $member['user_id']]['title'];
                     $member['admin'] = $members[(int) $member['user_id']]['admin'] ? '1' : '0';
                 }
             }
             $this->set('form_error', $e->getError());
         }
     }
     $this->set('group', $group);
     $this->addJSCode('Group.initEdit();');
 }
开发者ID:Godefroy,项目名称:iseplive,代码行数:95,代码来源:Group.php


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