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


PHP phpThumb::generateThumbnail方法代码示例

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


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

示例1: resizeImage

 /**
  * Resize an image
  *
  * Looks like a private function to me, but could be used as it is
  * 
  * @param $filename String Nom du fichier
  * @param $options Array Can override $settings and add these options :
  *				output : relative to 'folder' output image filename (default : $filename (overwrite))
  *				delete_source : if output is different from input, this set to true will delete the source file (default : false)
  * @return Returns true in case of success, false otherwise ($this->errors[$Model->name] gets populated)
  */
 function resizeImage(&$Model, $filepath, $options = array())
 {
     if (!file_exists($filepath)) {
         $this->errors[$Model->name][] = __('PhpThumb behavior : le fichier ', true) . $filepath . __(' n\'existe pas.', true);
         return false;
     }
     $settings = am(am($this->settings[$Model->name]['default'], array('output' => $filepath, 'delete_source' => false)), $options);
     App::import('Vendor', 'phpThumb', array('file' => 'phpThumb' . DS . 'phpthumb.class.php'));
     $phpThumb = new phpThumb();
     $phpThumb->setSourceFilename($filepath);
     $phpThumb->setParameter('w', $settings['width']);
     $phpThumb->setParameter('h', $settings['height']);
     if ($settings['zoomcrop'] === true) {
         //$phpThumb->setParameter('zc', 1);
     }
     if (!(0 == $settings['sx'] && 0 == $settings['sy'] && 0 == $settings['sw'] && 0 == $settings['sh'])) {
         $phpThumb->setParameter('sx', $settings['sx']);
         $phpThumb->setParameter('sy', $settings['sy']);
         $phpThumb->setParameter('sw', $settings['sw']);
         $phpThumb->setParameter('sh', $settings['sh']);
         if ($settings['aoe']) {
             $phpThumb->setParameter('aoe', 1);
         }
     }
     if (isset($settings['f'])) {
         $phpThumb->setParameter('f', $settings['f']);
     }
     if (!$phpThumb->generateThumbnail()) {
         /* Woopsy, the image couldn't be resized */
         debug($phpThumb->debugmessages);
         $this->errors[$Model->name][] = __('PhpThumb behavior : le fichier ', true) . $filepath . __(' n\'a pas pu être resizé', true);
         return false;
     }
     if (!$phpThumb->RenderToFile($settings['output'])) {
         /* File couldn't be created */
         $this->errors[$Model->name][] = __('PhpThumb behavior : le fichier ', true) . $settings['folder'] . $settings['output'] . __(' n\'a pas pu être créé', true);
         return false;
     }
     if ($settings['delete_source'] && $settings['output'] != $filepath) {
         if (!unlink($filepath)) {
             $this->errors[$Model->name][] = __('PhpThumb behavior : le fichier ', true) . $filepath . __(' n\'a pas pu être supprimé', true);
             return false;
         }
     }
     return true;
 }
开发者ID:kouak,项目名称:ircube,代码行数:57,代码来源:php_thumb.php

示例2: createthumb

 /**
  * Creation of an image thumbnail
  *
  * @param $name String File name on server
  * @param $filename String Final file name
  * @param $new_w Int Width in px
  * @param $new_h Int Height in px
  * @param $zc Bool "Zoom crop" (if true, cuts the largest possible square from the image center)
  */
 function createthumb($name, $filename, $new_w, $new_h, $zc)
 {
     App::import(array('file' => 'vendors' . DS . 'phpThumb' . DS . 'phpthumb.class.php', 'name' => 'MeioUpload.phpThumb', 'type' => 'file'));
     //mod_rewriteが使用できない場合にパスにindex.phpが入ってしまうため
     //絶対パスに変更
     if (Configure::read('App.baseUrl')) {
         $name = WWW_ROOT . $name;
         $filename = WWW_ROOT . $filename;
     }
     $phpThumb = new phpThumb();
     $phpThumb->config_allow_src_above_docroot = true;
     $phpThumb->setSourceFilename($name);
     $phpThumb->setParameter('w', $new_w);
     $phpThumb->setParameter('h', $new_h);
     $phpThumb->setParameter('zc', $zc);
     $parts = pathinfo($filename);
     //vd($parts);die();
     $phpThumb->setParameter('f', $parts['extension']);
     if ($phpThumb->generateThumbnail()) {
         $phpThumb->RenderToFile($filename);
     } else {
         die($phpThumb->fatalerror);
     }
 }
开发者ID:masayukiando,项目名称:googlemap-search_ActionScript3.0,代码行数:33,代码来源:meio_upload.php

示例3: generateThumb

 /**
  * This is the method that actually does the thumbnail generation by setting up
  * the parameters and calling phpThumb
  *
  * @return bool Success?
  * @author Nate Constant
  **/
 function generateThumb($baseDir, $dir, $filename, $size, $options = array())
 {
     // Make sure we have the name of the uploaded file and that the Model is specified
     if (empty($baseDir) || empty($filename)) {
         Debugger::log('Base directory or filename is empty');
         return false;
     }
     $source = $baseDir . $dir . $filename;
     if (empty($size)) {
         $height = 100;
         $width = 100;
     } else {
         $height = $size['height'];
         $width = $size['width'];
     }
     // verify that the size is greater than 0 ( emtpy file uploaded )
     if (filesize($baseDir . $dir . $filename === 0)) {
         Debugger::log('File is empty');
         return false;
     }
     // verify that the filesystem is writable, if not add an error to the object
     // dont fail if not and let phpThumb try anyway
     $cacheDir = $baseDir . 'cache' . DS;
     if (!file_exists($cacheDir)) {
         debugger::log('Cache directory doesn\'t exist');
         if (!mkdir($cacheDir)) {
             Debugger::log('Can\' create ' . $cacheDir);
             return false;
         }
     }
     if (!is_writable($cacheDir)) {
         debugger::log($cacheDir . ' not writable');
         chmod($cacheDir, 0777);
     }
     // Load phpThumb
     App::import('Vendor', 'phpThumb', array('file' => 'phpThumb/phpthumb.class.php'));
     $phpThumb = new phpThumb();
     // phpThumb configs
     $phpThumb->setParameter('config_cache_force_passthru', false);
     $phpThumb->setParameter('config_allow_src_above_docroot', true);
     // ignore aspect ratio and allow enlarging
     //		$phpThumb->setParameter('iar', 1);
     // image configs
     $phpThumb->setSourceFilename($source);
     $phpThumb->setParameter('w', $width);
     $phpThumb->setParameter('h', $height);
     // auto rotate based on exif data
     $phpThumb->setParameter('ar', 'x');
     foreach ($options as $key => $val) {
         $phpThumb->setParameter($key, $val);
     }
     //		$phpThumb->setParameter('zc', 1);
     if ($phpThumb->generateThumbnail()) {
         if (!$phpThumb->RenderToFile($cacheDir . $filename . '-' . $height . 'x' . $width . '.jpg')) {
             Debugger::log('Could not render to file');
             return false;
         }
     } else {
         Debugger::log('Could not generate thumbnail');
         return false;
     }
     return true;
 }
开发者ID:RobertWHurst,项目名称:Telame,代码行数:70,代码来源:thumb.php

示例4: thumb

 public function thumb($file, $dest_file = false)
 {
     if (empty($file) or !file_exists($file)) {
         return false;
     }
     /*
      * load phpThumb from vendors directory
      * and get a new instance
      */
     App::import('Vendor', 'phpThumb', array('file' => 'phpThumb' . DS . 'phpthumb.class.php'));
     $phpThumb = new phpThumb();
     // configure phpThumb for it's thumbnail generation
     $phpThumb->setSourceFilename($file);
     $phpThumb->setParameter('w', $this->width);
     $phpThumb->setParameter('h', $this->height);
     $phpThumb->setParameter('zc', $this->zoom_crop);
     /*
      * generate thumbnail
      * and render to file
      */
     $pathinfo = pathinfo($file);
     if ($dest_file) {
         $destination = $this->save_paths['thumb'] . $dest_file;
     } else {
         $destination = $this->save_paths['thumb'] . md5($pathinfo['filename'] . $this->width . $this->height . $this->zoom_crop) . '.' . $pathinfo['extension'];
     }
     /*
      * if their is an older version of the thumbnail
      * (same source, width, height, zoom-crop),
      * then delete
      */
     if (file_exists($destination)) {
         @unlink($destination);
     }
     if ($phpThumb->generateThumbnail() and $phpThumb->RenderToFile($destination)) {
         return $destination;
     } else {
         // something goes wrong
         return false;
     }
 }
开发者ID:trungjc,项目名称:collegeprospectnetwork,代码行数:41,代码来源:ImageComponent.php


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