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


PHP Image::thumbnail方法代码示例

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


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

示例1: testThumbnail

 public function testThumbnail()
 {
     $image = new Image();
     $image->path = '/path/to/image.png';
     $thumbnail = $image->thumbnail('w:128;h:128');
     $this->assertInstanceOf('ICanBoogie\\Modules\\Thumbnailer\\Thumbnail', $thumbnail);
 }
开发者ID:icybee,项目名称:module-images,代码行数:7,代码来源:ImageTest.php

示例2: __construct

 /**
  * Constructor
  *
  * Parses arguments, looks for a command, and hands off command
  * options to another Relic library function.
  */
 public function __construct()
 {
     $this->_parseArgs();
     if (array_key_exists($this->command, $this->commands)) {
         $args = $this->_parseOpts($this->commands[$this->command]['options'], $this->commands[$this->command]['params']);
         switch ($this->command) {
             case 'thumb':
                 Image::thumbnail($args['params']['image'], $args['params']['dst'], $args['options']);
                 break;
             case 'split':
                 PDF::split($args);
                 break;
             case 'metadata':
                 $mime = Mime::mime($args['params']['file']);
                 if (in_array($mime, array('image/jpg', 'image/jpeg', 'image/tiff'))) {
                     $image = new Image($args['params']['file']);
                     $this->prettyPrint($image->exif());
                 } else {
                     if ($mime == 'application/pdf') {
                         $pdf = new PDF($args['params']['file']);
                         $this->prettyPrint($pdf->info);
                     }
                 }
                 break;
             case 'mime':
                 Mime::printMime($args['params']['file']);
                 break;
         }
     } else {
         $this->_usage(false, 'Unknown command.');
         exit(1);
     }
 }
开发者ID:ndreynolds,项目名称:arcs,代码行数:39,代码来源:CommandLine.php

示例3: make_thumb

 public function make_thumb($width, $height = 0)
 {
     $img = $this->input->post('image');
     //die($img);
     if ($img == false) {
         die('FALSE');
     }
     $im = new Image($img);
     echo $im->thumbnail($width, $height)->url;
 }
开发者ID:jotavejv,项目名称:CMS,代码行数:10,代码来源:images.php

示例4: add

 /**
  * file agregator
  *
  * adds a file to an ad
  *
  * @param   mixed   $file
  * @param   mixed   $target     a blank parameter in which the
  *                              target file witll be written
  * @access  public
  * @return  Boolean
  */
 public function add($file, &$target)
 {
     $target = $this->_generateFilename($file);
     $up_pic = self::target($target);
     $up_thm = self::target($target, true);
     $stored = $this->uploaded_and_stored($file, $up_pic);
     // do not create thumbnails if file is not supported (pdf)
     if (Image::isValidType(Image::getType($up_pic))) {
         Image::thumbnail($up_pic, $up_thm, 333);
     }
     return !Image::isError() && $stored;
 }
开发者ID:jimiyash,项目名称:cake-pluggables,代码行数:23,代码来源:upload.php

示例5: add_photo

 /**
  * 用flash添加照片
  */
 function add_photo()
 {
     if ($_FILES) {
         global $php;
         $php->upload->thumb_width = 136;
         $php->upload->thumb_height = 136;
         $php->upload->max_width = 500;
         $php->upload->max_height = 500;
         $php->upload->thumb_qulitity = 100;
         if (class_exists('SaeStorage', false)) {
             $s = new SaeStorage();
             $file_id = uniqid('pic_', false) . mt_rand(1, 100);
             $tmp_file = SAE_TMP_PATH . '/thum_' . $file_id . '.jpg';
             Image::thumbnail($_FILES['Filedata']['tmp_name'], $tmp_file, $php->upload->thumb_width, $php->upload->thumb_height, $php->upload->thumb_qulitity, false);
             $pic = '/uploads/' . $file_id . ".jpg";
             $ret = $s->upload('static', $pic, $_FILES['Filedata']['tmp_name']);
             if ($ret) {
                 $data['picture'] = $s->getUrl('static', $pic);
             } else {
                 echo $s->errmsg() . ' : ' . $s->errno();
                 return;
             }
             $thum_pic = '/uploads/thum_' . $file_id . '.jpg';
             $ret = $s->upload('static', $thum_pic, $tmp_file);
             if ($ret) {
                 $data['imagep'] = $s->getUrl('static', $thum_pic);
             } else {
                 echo $s->errmsg() . ' : ' . $s->errno();
                 return;
             }
         } else {
             $php->upload->sub_dir = 'user_images';
             $up_pic = Swoole::$php->upload->save('Filedata');
             if (empty($up_pic)) {
                 return '上传失败,请重新上传! Error:' . $php->upload->error_msg;
             }
             $data['picture'] = $up_pic['name'];
             $data['imagep'] = $up_pic['thumb'];
         }
         $data['uid'] = $_POST['uid'];
         $up_pic['photo_id'] = $this->swoole->model->UserPhoto->put($data);
         /* if(isset($_POST['post']))
            {
            	Api::feed('photo', $data['uid'], 0, $up_pic['photo_id']);
            } */
         return json_encode($up_pic);
     } else {
         $this->swoole->tpl->display('myphoto_add_photo.html');
     }
 }
开发者ID:netstao,项目名称:swoole.com,代码行数:53,代码来源:myphoto.php

示例6: add

 /**
  * add
  *
  * aggregates a image to the file system prefixing its name with
  * company id.
  *
  * @param string $type the type of image that is being uploaded,
  * a valid type can be a lowercassed model name to which images
  * are to be mapped
  * @param string $company_id company id to prefix the filename
  *
  * @access public
  * @return boolean
  */
 public function add($type, $company_id)
 {
     if (!$this->found()) {
         return false;
     }
     $name = $this->file['name'];
     $source = $this->file['tmp_name'];
     $img_dir = "img/uploads/{$type}";
     $tmb_dir = "img/uploads/{$type}/small";
     $file_format = WWW_ROOT . '%s/%s_%s';
     $target_file = sprintf($file_format, $img_dir, $company_id, $name);
     $thumbl_file = sprintf($file_format, $tmb_dir, $company_id, $name);
     $uploaded = is_uploaded_file($source);
     if ($uploaded && move_uploaded_file($source, $target_file)) {
         Image::thumbnail($target_file, $thumbl_file, 200);
     }
     return file_exists($target_file) && file_exists($thumbl_file);
 }
开发者ID:jimiyash,项目名称:cake-pluggables,代码行数:32,代码来源:image.php

示例7: file

 public function file($type, $src)
 {
     $types = Configure::read('thumbnail');
     if (!in_array($type, array_keys($types))) {
         $this->controller->_stop();
     }
     $dest = $this->getFileThumbnail($type, $src);
     if (!file_exists($dest) || filemtime($dest) < filemtime($src)) {
         App::import('vendor', 'inc/image');
         try {
             $img = new Image($src);
             $img->thumbnail($dest, $types[$type][0], $types[$type][1]);
         } catch (ImageNullException $e) {
             $this->controller->_stop();
         }
     }
     $this->controller->header('Content-Type: image/jpeg');
     echo file_get_contents($dest);
     $this->controller->_stop();
 }
开发者ID:tilitala,项目名称:nForum,代码行数:20,代码来源:thumbnail.php

示例8: by_size

 public static function by_size($file_path, $width, $height, $force = false)
 {
     $width = empty($width) || !is_numeric($width) ? '96' : $width;
     $height = empty($height) || !is_numeric($height) ? '96' : $height;
     $thumb = self::normalize_thumb($file_path, $width, $height);
     if ($force) {
         $prefix = substr($file_path, 0, strrpos($file_path, '.'));
         $ext = substr($file_path, strrpos($file_path, '.') + 1);
         // remove all cached thumbnails so they get regenerated
         foreach (glob("{$prefix}*.*x*.{$ext}") as $file) {
             @unlink($file);
         }
     }
     $file = str_replace('//', '/', dirname($file_path) . "/" . basename($thumb));
     if (!file_exists($thumb)) {
         if (!Image::thumbnail($file_path, $width, $height)) {
             return false;
         }
     }
     return str_replace(PartuzaConfig::get('site_root'), '', $file);
 }
开发者ID:dalinhuang,项目名称:shopexts,代码行数:21,代码来源:Image.php

示例9: process_template

 public function process_template($newdomitem, $i, $page)
 {
     $single = $this->_IU->input->get('read');
     $logged_in = !empty($this->_IU->user);
     //set title, and link it if it's <a> tag
     $titlefield = $newdomitem->find('.iu-item-title');
     foreach ($titlefield as $field) {
         $field->innertext = $i->title;
         if (strtolower(trim($field->tag)) == 'a') {
             if (!empty($single)) {
                 $field->href = 'javascript:;';
             } else {
                 $format = empty($field->{'data-format'}) ? '%page_url%?%read_slug%=%seo_title%' : (string) $field->{'data-format'};
                 $seo_title = $i->id . '-' . cyr_url_title($i->title);
                 $url = str_replace('%page_url%', site_url($page->uri), $format);
                 $url = str_replace('%read_slug%', $this->read_slug, $url);
                 $url = str_replace('%seo_title%', $seo_title, $url);
                 $url = str_replace('%base_url%', base_url(), $url);
                 $url = str_replace('%site_url%', site_url(), $url);
                 $field->href = $url;
             }
         }
     }
     //set link for <a> element; usable for "read more" links
     $itemlnks = $newdomitem->find('.iu-item-url');
     foreach ($itemlnks as $lnk) {
         if (strtolower(trim($lnk->tag)) != 'a') {
             continue;
         }
         $format = empty($lnk->{'data-format'}) ? '%page_url%?%read_slug%=%seo_title%' : (string) $lnk->{'data-format'};
         $seo_title = $i->id . '-' . cyr_url_title($i->title);
         $url = str_replace('%page_url%', site_url($page->uri), $format);
         $url = str_replace('%read_slug%', $this->read_slug, $url);
         $url = str_replace('%seo_title%', $seo_title, $url);
         $url = str_replace('%base_url%', base_url(), $url);
         $url = str_replace('%site_url%', site_url(), $url);
         $lnk->href = $url;
     }
     //fill out author name
     $authorfield = $newdomitem->find('.iu-item-author');
     foreach ($authorfield as $field) {
         $field->innertext = $i->user->get()->name;
     }
     //fill out text field
     $textfield = $newdomitem->find('.iu-item-text');
     foreach ($textfield as $field) {
         $limit = empty($field->{'data-limit'}) ? 0 : (int) $field->{'data-limit'};
         //never show excerpt to a logged in user
         if ($logged_in) {
             $shortened = false;
         } else {
             $shortened = $single == false && $limit > 0;
         }
         if ($shortened) {
             $format = empty($field->{'data-format'}) ? '%page_url%?%read_slug%=%seo_title%' : (string) $field->{'data-format'};
             $readmore = empty($field->{'data-readmore'}) ? 'read more &raquo;' : (string) $field->{'data-readmore'};
             $seo_title = $i->id . '-' . cyr_url_title($i->title);
             $url = str_replace('%page_url%', site_url($page->uri), $format);
             $url = str_replace('%read_slug%', $this->read_slug, $url);
             $url = str_replace('%seo_title%', $seo_title, $url);
             $url = str_replace('%base_url%', base_url(), $url);
             $url = str_replace('%site_url%', site_url(), $url);
             $field->href = $url;
             $field->innertext = character_limiter($i->text, $limit);
             $field->innertext .= ' <a href="' . $url . '" class="iu-read-more">' . $readmore . '</a>';
         } else {
             $field->innertext = $i->text;
         }
     }
     //set images (and resize them)
     $images = $newdomitem->find('.iu-item-image');
     foreach ($images as $img) {
         if (strtolower(trim($img->tag)) != 'img') {
             continue;
         }
         $width = preg_replace('/[^0-9]+/', '', $img->width);
         if (empty($width)) {
             $width = 300;
         }
         $height = preg_replace('/[^0-9]+/', '', $img->height);
         if (empty($height)) {
             $height = 0;
         }
         $im = new Image($i->image);
         $img->src = $im->thumbnail($width, $height)->url;
         $img->setAttribute('data-fullimg', $im->uri);
         $img->alt = $img->title = $i->title;
         if (!empty($single)) {
             $img->onclick = 'return iu_popup_image(this, \'' . $i->title . '\');';
         }
     }
     //set image links for <a> elements
     $imagelnks = $newdomitem->find('.iu-item-image-url');
     foreach ($imagelnks as $lnk) {
         if (strtolower(trim($lnk->tag)) != 'a') {
             continue;
         }
         if (!empty($i->image)) {
             $im = new Image($i->image);
             $lnk->href = $im->url;
//.........这里部分代码省略.........
开发者ID:jotavejv,项目名称:CMS,代码行数:101,代码来源:Repeatable.php

示例10: save

 function save($name, $filename = null, $allow = null)
 {
     //检查请求中是否存在上传的文件
     if (empty($_FILES[$name]['type'])) {
         $this->error_msg = "No upload file '{$name}'!";
         $this->error_code = 0;
         return false;
     }
     //最终相对目录
     $base_dir = empty($this->sub_dir) ? $this->sub_dir : $this->base_dir . "/" . $this->sub_dir;
     //切分目录
     if ($this->shard_type == 'randomkey') {
         if (empty($this->shard_argv)) {
             $this->shard_argv = 8;
         }
         $up_dir = $base_dir . "/" . RandomKey::randmd5($this->shard_argv);
     } elseif ($this->shard_type == 'user') {
         $up_dir = $base_dir . "/" . $this->shard_argv;
     } else {
         if (empty($this->shard_argv)) {
             $this->shard_argv = 'Ym/d';
         }
         $up_dir = $base_dir . "/" . date($this->shard_argv);
     }
     //上传的最终绝对路径,如果不存在则创建目录
     $path = WEBPATH . $up_dir;
     if (!is_dir($path)) {
         if (mkdir($path, 0777, true) === false) {
             $this->error_msg = "mkdir path={$path} fail.";
             return false;
         }
     }
     //MIME格式
     $mime = $_FILES[$name]['type'];
     $filetype = $this->mime_type($mime);
     if ($filetype === 'bin') {
         $filetype = self::file_ext($_FILES[$name]['name']);
     }
     if ($filetype === false) {
         $this->error_msg = "File mime '{$mime}' unknown!";
         $this->error_code = 1;
         return false;
     } elseif (!in_array($filetype, $this->allow)) {
         $this->error_msg = "File Type '{$filetype}' not allow upload!";
         $this->error_code = 2;
         return false;
     }
     //生成文件名
     if ($filename === null) {
         $filename = RandomKey::randtime();
         //如果已存在此文件,不断随机直到产生一个不存在的文件名
         while ($this->exist_check and is_file($path . '/' . $filename . '.' . $filetype)) {
             $filename = RandomKey::randtime();
         }
     } elseif ($this->overwrite === false and is_file($path . '/' . $filename . '.' . $filetype)) {
         $this->error_msg = "File '{$path}/{$filename}.{$filetype}' existed!";
         $this->error_code = 3;
         return false;
     }
     if ($this->shard_type != 'user') {
         $filename .= '.' . $filetype;
     }
     //检查文件大小
     $filesize = filesize($_FILES[$name]['tmp_name']);
     if ($this->max_size > 0 and $filesize > $this->max_size) {
         $this->error_msg = "File size go beyond the max_size!";
         $this->error_code = 4;
         return false;
     }
     $save_filename = $path . "/" . $filename;
     //写入文件
     if (self::moveUploadFile($_FILES[$name]['tmp_name'], $save_filename)) {
         //产生缩略图
         if ($this->thumb_width and in_array($filetype, array('gif', 'jpg', 'jpeg', 'bmp', 'png'))) {
             if (empty($this->thumb_dir)) {
                 $this->thumb_dir = $up_dir;
             }
             $thumb_file = $this->thumb_dir . '/' . $this->thumb_prefix . $filename;
             Image::thumbnail($save_filename, WEBPATH . $thumb_file, $this->thumb_width, $this->thumb_height, $this->thumb_qulitity);
             $return['thumb'] = $thumb_file;
         }
         //压缩图片
         if ($this->max_width and in_array($filetype, array('gif', 'jpg', 'jpeg', 'bmp', 'png'))) {
             Image::thumbnail($save_filename, $save_filename, $this->max_width, $this->max_height, $this->max_qulitity);
         }
         $return['name'] = "{$up_dir}/{$filename}";
         $return['size'] = $filesize;
         $return['type'] = $filetype;
         return $return;
     } else {
         $this->error_msg = "move upload file fail. tmp_name={$_FILES[$name]['tmp_name']}|dest_name={$save_filename}";
         $this->error_code = 2;
         return false;
     }
 }
开发者ID:jinguanio,项目名称:swoolecrawler,代码行数:95,代码来源:Upload.php

示例11: handleExternal

 /**
  * Handles adding a media item from an external source, such as YouTube.
  *
  * @param array $fd
  * @return array
  */
 protected function handleExternal(array $fd)
 {
     try {
         parse_str(parse_url($fd['external']['youtube_url'], PHP_URL_QUERY), $queryArgs);
         if (empty($queryArgs['v'])) {
             throw new Media_Exception(t('Please provide a valid YouTube URL'));
         }
         $serviceId = $queryArgs['v'];
         $externalMedia = Externalmedia::factory($fd['external']['service'], $serviceId);
     } catch (ExternalMediaDriver_InvalidID $e) {
         throw new Media_Exception(t('Please provide a valid YouTube URL'));
     } catch (Externalmedia_Exception $e) {
         throw new Media_Exception($e->getMessage());
     }
     // Generate a random directory as the uploader would, to store thumbnail
     $uploadDir = $this->_zula->getDir('uploads') . '/media/' . $fd['cid'] . '/external';
     if ($dirname = zula_make_unique_dir($uploadDir)) {
         $uploadDir .= '/' . $dirname;
         $thumbname = $dirname . '_thumb.png';
         if (copy($externalMedia->thumbUrl, $uploadDir . '/' . $thumbname)) {
             // Resize the thumbnail image
             try {
                 $thumbnailWH = $this->_config->get('media/thumb_dimension');
                 $thumbnail = new Image($uploadDir . '/' . $thumbname);
                 $thumbnail->mime = 'image/png';
                 $thumbnail->thumbnail($thumbnailWH, $thumbnailWH);
                 $thumbnail->save();
             } catch (Image_Exception $e) {
                 $this->_event->error(t('Oops, an error occurred while processing an image'));
                 $this->_log->message($e->getMessage(), Log::L_WARNING);
             }
         } else {
             $this->_event->error(t('Unable to save thumbnail image'));
             $thumbname = null;
         }
         return array(array('title' => empty($fd['title']) ? $externalMedia->title : $fd['title'], 'desc' => empty($fd['desc']) ? $externalMedia->description : $fd['desc'], 'type' => 'external', 'file' => '', 'thumbnail' => isset($thumbname) ? $dirname . '/' . $thumbname : '', 'external' => array('service' => $fd['external']['service'], 'id' => $serviceId)));
     } else {
         throw new Media_Exception(t('Unable to create directory'));
     }
 }
开发者ID:jinshana,项目名称:tangocms,代码行数:46,代码来源:add.php

示例12: actionUpdate

 /**
  * Updates an existing User model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         $model->file = UploadedFile::getInstance($model, 'file');
         if ($model->file && $model->validate()) {
             //TODO: Посмотреть, может возможно изменять размер картинки до загрузки на сервер
             $image_name = 'user_' . $id . '.' . $model->file->extension;
             $image_full_name = Yii::$app->params['user']['image']['path'] . $image_name;
             $model->file->saveAs($image_full_name);
             Image::thumbnail($image_full_name, Yii::$app->params['user']['image']['width'], Yii::$app->params['user']['image']['height'])->save(Yii::getAlias($image_full_name), ['quality' => 100]);
             $model->image = $image_name;
         }
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
开发者ID:obedkin,项目名称:atlant,代码行数:25,代码来源:DefaultController.php

示例13: ajax_face

 /**
  * page for upload face in iframe
  * override the js array
  */
 public function ajax_face()
 {
     if (!$this->RequestHandler->isPost()) {
         $this->error(ECode::$SYS_REQUESTERROR);
     }
     $this->requestLogin();
     $u = User::getInstance();
     $face = Configure::read("user.face");
     //init upload file
     if (isset($this->params['url']['name'])) {
         //html5 mode
         $tmp_name = tempnam(CACHE, "upload_");
         file_put_contents($tmp_name, file_get_contents('php://input'));
         $file = array('tmp_name' => $tmp_name, 'name' => nforum_iconv('utf-8', $this->encoding, $this->params['url']['name']), 'size' => filesize($tmp_name), 'error' => 0);
     } else {
         if (isset($this->params['form']['file']) && is_array($this->params['form']['file'])) {
             //flash mode
             $file = $this->params['form']['file'];
             $file['name'] = nforum_iconv('utf-8', $this->encoding, $file['name']);
         } else {
             $this->error(ECode::$ATT_NONE);
         }
     }
     $errno = isset($file['error']) ? $file['error'] : UPLOAD_ERR_NO_FILE;
     switch ($errno) {
         case UPLOAD_ERR_OK:
             $tmpFile = $file['tmp_name'];
             $tmpName = $file['name'];
             if (!isset($tmp_name) && !is_uploaded_file($tmpFile)) {
                 $msg = "上传错误";
                 break;
             }
             $ext = strrchr($tmpName, '.');
             if (!in_array(strtolower($ext), $face['ext'])) {
                 $msg = "上传文件扩展名有误";
                 break;
             }
             if (filesize($tmpFile) > $face['size']) {
                 $msg = "文件大小超过上限" . $face['size'] / 1024 . "K";
                 break;
             }
             mt_srand();
             $faceDir = $face['dir'] . DS . strtoupper(substr($u->userid, 0, 1));
             $facePath = $faceDir . DS . $u->userid . "." . mt_rand(0, 10000) . $ext;
             $faceFullDir = WWW_ROOT . $faceDir;
             $faceFullPath = WWW_ROOT . $facePath;
             if (!is_dir($faceFullDir)) {
                 @mkdir($faceFullDir);
             }
             if (is_file($faceFullPath)) {
                 $msg = "我觉得您今天可以买彩票了";
                 break;
             }
             if (isset($tmp_name)) {
                 if (!rename($tmp_name, $faceFullPath)) {
                     $msg = "上传错误";
                     break;
                 }
             } else {
                 if (!move_uploaded_file($tmpFile, $faceFullPath)) {
                     $msg = "上传错误";
                     break;
                 }
             }
             App::import('vendor', "inc/image");
             try {
                 $img = new Image($faceFullPath);
                 $format = $img->getFormat();
                 if (!in_array($format, range(1, 3))) {
                     $msg = "上传的文件貌似不是图像文件";
                     break;
                 }
                 //gif do not thumbnail
                 if ($format != 1) {
                     $facePath = preg_replace("/\\.[^.]+\$/", '.jpg', $facePath);
                     $faceFullPath = WWW_ROOT . $facePath;
                     $img->thumbnail($faceFullPath, 120, 120);
                 }
             } catch (ImageNullException $e) {
                 $msg = "上传的文件貌似不是图像文件";
                 break;
             }
             $this->set("no_html_data", array("img" => $facePath, "width" => $img->getWidth(), "height" => $img->getHeight(), "ajax_st" => 1, "ajax_code" => ECode::$SYS_AJAXOK, "ajax_msg" => "文件上传成功"));
             return;
             break;
         case UPLOAD_ERR_INI_SIZE:
         case UPLOAD_ERR_FORM_SIZE:
             $msg = "文件大小超过系统上限";
             break;
         case UPLOAD_ERR_PARTIAL:
             $msg = "文件传输出错!";
             break;
         case UPLOAD_ERR_NO_FILE:
             $msg = "没有文件上传!";
             break;
         default:
//.........这里部分代码省略.........
开发者ID:rainsun,项目名称:nForum,代码行数:101,代码来源:user_controller.php

示例14: testThumbnailofWideImage

 public function testThumbnailofWideImage()
 {
     $src = dirname(__FILE__) . '/assets/D.jpg';
     $expected_dst = dirname(__FILE__) . '/assets/D.expected_thumb.jpg';
     $actual_dst = dirname(__FILE__) . '/assets/D.actual_thumb.jpg';
     if (file_exists($actual_dst)) {
         unlink($actual_dst);
     }
     $result = Image::thumbnail($src, $actual_dst, 200, 200);
     // Test height and width
     $info = getimagesize($result);
     $this->assertFalse(empty($info));
     $this->assertEquals($info[0], 200);
     $this->assertEquals($info[1], 200);
     // Test signature
     $actual_sig = md5_file($actual_dst);
     $expected_sig = md5_file($expected_dst);
     $this->assertEquals($actual_sig, $expected_sig);
     if (file_exists($actual_dst)) {
         unlink($actual_dst);
     }
 }
开发者ID:craftsmancoding,项目名称:image,代码行数:22,代码来源:imageTest.php

示例15: process_template

 public function process_template($newdomitem, $i, $page, $content)
 {
     //$single = $this->_IU->input->get('read');
     $logged_in = !empty($this->_IU->user);
     //set title, and link it if it's <a> tag
     $titlefield = $newdomitem->find('.iu-gallery-title');
     foreach ($titlefield as $field) {
         $field->innertext = $i->title;
         if (strtolower(trim($field->tag)) == 'a') {
             $format = empty($field->{'data-format'}) ? '%page_url%?%read_slug%=%seo_title%' : (string) $field->{'data-format'};
             $seo_title = $i->id . '-' . cyr_url_title($i->title);
             $url = str_replace('%page_url%', site_url($page->uri), $format);
             $url = str_replace('%read_slug%', $this->read_slug, $url);
             $url = str_replace('%seo_title%', $seo_title, $url);
             $url = str_replace('%base_url%', base_url(), $url);
             $url = str_replace('%site_url%', site_url(), $url);
             $field->href = $url;
         }
     }
     //set link for <a> element; usable for "read more" links
     $itemlnks = $newdomitem->find('.iu-gallery-url');
     foreach ($itemlnks as $lnk) {
         if (strtolower(trim($lnk->tag)) != 'a') {
             continue;
         }
         $format = empty($lnk->{'data-format'}) ? '%page_url%?%read_slug%=%seo_title%' : (string) $lnk->{'data-format'};
         $seo_title = $i->id . '-' . cyr_url_title($i->title);
         $url = str_replace('%page_url%', site_url($page->uri), $format);
         $url = str_replace('%read_slug%', $this->read_slug, $url);
         $url = str_replace('%seo_title%', $seo_title, $url);
         $url = str_replace('%base_url%', base_url(), $url);
         $url = str_replace('%site_url%', site_url(), $url);
         $lnk->href = $url;
     }
     //fill out author name
     $authorfield = $newdomitem->find('.iu-gallery-author');
     foreach ($authorfield as $field) {
         $field->innertext = $i->user->get()->name;
     }
     //fill out text field
     $textfield = $newdomitem->find('.iu-gallery-text');
     foreach ($textfield as $field) {
         $limit = empty($field->{'data-limit'}) ? 0 : (int) $field->{'data-limit'};
         $field->innertext = $i->text;
     }
     //set images (and resize them)
     $images = $newdomitem->find('.iu-gallery-image');
     foreach ($images as $img) {
         if (strtolower(trim($img->tag)) != 'img') {
             continue;
         }
         $width = preg_replace('/[^0-9]+/', '', $img->width);
         if (empty($width)) {
             $width = 300;
         }
         $height = preg_replace('/[^0-9]+/', '', $img->height);
         if (empty($height)) {
             $height = 0;
         }
         $jackbox = empty($newdomitem->{'data-no-lightbox'}) ? true : false;
         $im = new Image($i->image);
         $img->src = $im->thumbnail($width, $height)->url;
         $img->setAttribute('data-fullimg', $im->uri);
         $img->alt = $img->title = $i->title;
         if ($jackbox) {
             $img->onclick = 'return iu_popup_gallery_image($(this));';
         }
         $img->id = 'iu_image_' . $i->id;
         $img->setAttribute('data-group', $content->div);
         $img->setAttribute('data-title', $i->title);
         $img->setAttribute('data-href', $i->image);
         $img->setAttribute('data-description', '#iu_gallery_desc_' . $i->id);
         /*$classesarr = empty($img->class) ? array() : explode(' ', $img->class);
         		$classesarr[] = 'iu-gallery-member';
         		$img->class = implode(' ', $classesarr); //*/
     }
     //set image links for <a> elements
     $imagelnks = $newdomitem->find('.iu-gallery-image-url');
     foreach ($imagelnks as $lnk) {
         if (strtolower(trim($lnk->tag)) != 'a') {
             continue;
         }
         if (!empty($i->image)) {
             $im = new Image($i->image);
             $lnk->href = $im->url;
         }
     }
     //set date
     $datefield = $newdomitem->find('.iu-gallery-date');
     foreach ($datefield as $field) {
         $format = empty($field->{'data-format'}) ? Setting::value('datetime_format', 'F j, Y @ H:i') : $field->{'data-format'};
         $field->innertext = date($format, $i->timestamp);
     }
     /*//add id
     		$idfield = $newdomitem->find('.iu-gallery-item-id', 0);
     		if (!empty($idfield))
     			$idfield->value = $i->id;
     		else
     			$newdomitem->innertext .= '<input type="hidden" class="iu-gallery-item-id" value="'.$i->id.'" />';
     
//.........这里部分代码省略.........
开发者ID:jotavejv,项目名称:CMS,代码行数:101,代码来源:Gallery.php


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