create() protected method

Calls the driver function and creates the thumbnail
protected create ( )
Exemplo n.º 1
0
 public function action_index()
 {
     $group = $this->request->param('group');
     if (!$group) {
         throw new HTTP_Exception_404();
     }
     $config = Kohana::$config->load('thumb')->get($group);
     if (!$config) {
         throw new HTTP_Exception_404();
     }
     $file = $this->request->param('file');
     if (!$file) {
         throw new HTTP_Exception_404();
     }
     $path = Arr::get($config, 'path', '');
     if (!empty($path)) {
         $path = rtrim($path, '/') . '/';
     }
     $thumb = Thumb::create($group, $path . $file);
     if ($thumb) {
         // Get the extension from the filename
         $ext = strtolower(pathinfo($thumb, PATHINFO_EXTENSION));
         $mime = File::mime_by_ext($ext);
         $this->response->headers('Content-Type', $mime ? $mime : 'image/jpeg');
         $this->response->body(file_get_contents($thumb));
     } else {
         throw new HTTP_Exception_500();
     }
 }
Exemplo n.º 2
0
 public function action_bmp()
 {
     $source = '128919316276.jpg';
     $thumb = new Thumb();
     $thumb->create($source, 130, 130);
     // $img = $thumb->imagecreatefrombmp($source);
     $this->auto_render = false;
 }
Exemplo n.º 3
0
 /**
  * 编辑图片
  */
 public function action_picedit()
 {
     $this->checklogin();
     $this->template->pid = $pid = (int) $this->getRequest('pid');
     $this->template->zoom = $zoom = trim($this->getQuery('zoom'));
     $this->template->info = $info = ORM::factory('img')->where('imgs.userid', '=', (int) $this->auth['uid'])->where('imgs.id', '=', $pid)->find();
     if (empty($info->picname)) {
         $this->show_message('非法访问', 0, array(), true);
     }
     $url = "http://" . $info->disk_id . '.wal8.com/';
     $picname = $info->disk_name . '/' . $info->picname;
     $thumb = new Thumb();
     if ($zoom == 'medium') {
         $picname = $thumb->create($picname, 640, 640, 's');
     } elseif ($zoom == 'thumb') {
         $picname = $thumb->create($picname, 130, 130);
     }
     $this->template->picname = $url . $picname;
     if ($this->isPost()) {
         $editName = trim($this->getPost('name'));
         $pid = (int) $this->getPost('pid');
         $set['custom_name'] = $editName;
         if (!empty($_FILES['newfile']['name'])) {
             $disks = ORM::factory('img_disk')->where('is_use', '=', 1)->find();
             $save_dir = ORM::factory('user', (int) $this->auth['uid'])->save_dir;
             $savePath = DOCROOT . '' . $disks->disk_name . '/' . $save_dir . '/';
             $upload = new Upload(array('size' => 2024));
             try {
                 $upload->set_path($savePath);
                 $result = $upload->save($_FILES['newfile']);
                 //$set['picname'] = $result['saveName'];
                 $set['filename'] = $result['name'];
                 $set['custom_name'] = $result['name'];
                 $set['filesize'] = $result['size'];
                 $picPath = pathinfo($info->disk_name . '/' . $info->picname);
                 $img_dir = '/s/';
                 $img_dir2 = '/thumbnails/';
                 if (!empty($this->img_size)) {
                     foreach ($this->img_size as $key => $v) {
                         //标准图路径
                         $zoomPath = $picPath['dirname'] . $img_dir . $picPath['filename'] . $v;
                         @unlink(Io::strip(DOCROOT . $zoomPath . $picPath['extension']));
                         @unlink(Io::strip(DOCROOT . $zoomPath . 'jpg'));
                         //缩略图路径
                         $thumbPath = $info->disk_name . $img_dir2 . $picPath['filename'] . $v;
                         @unlink(Io::strip(DOCROOT . $thumbPath . $picPath['extension']));
                         @unlink(Io::strip(DOCROOT . $thumbPath . 'jpg'));
                         @unlink(Io::strip(DOCROOT . $thumbPath . 'gif'));
                     }
                     @unlink(Io::strip(DOCROOT . $info->disk_name . '/' . $info->picname));
                     $saveName = $disks->disk_name . '/' . $save_dir . '/' . $result['saveName'];
                     rename($saveName, DOCROOT . $info->disk_name . '/' . $info->picname);
                     $saveName = $disks->disk_name . '/' . $save_dir . '/' . $info->picname;
                     $url = 'http://' . $info->disk_id . '.wal8.com/';
                     $data = array('img_url' => $url . $this->thumb->create($saveName, 130, 130), 'add_time' => time(), 'uid' => $this->auth['uid']);
                     $this->squid_img($data);
                     $data['img_url'] = $url . $this->thumb->create($saveName, 640, 640, 's');
                     $this->squid_img($data);
                     $data['img_url'] = $url . $this->thumb->create($saveName, 120, 120);
                     $this->squid_img($data);
                     $data['img_url'] = $url . $saveName;
                     $this->squid_img($data);
                 }
             } catch (Exception $e) {
                 $this->show_message($e->getMessage(), 0, array(), true);
             }
         }
         DB::update('imgs')->set($set)->where('id', '=', $pid)->execute();
         $sum = DB::select(DB::expr("sum(filesize) as sums"))->from('imgs')->where('userid', '=', $this->auth['uid'])->execute()->get('sums');
         DB::update('users')->set(array('use_space' => $sum))->where('uid', '=', $this->auth['uid'])->execute();
         ORM::factory('user')->upcache($this->auth['uid']);
         $links[] = array('text' => '重载图片编辑', 'href' => '/pic/picedit?pid=' . $pid);
         $this->show_message('修改图片处理成功', 1, $links, true);
     }
 }
 public function thumb($path, $windth, $height)
 {
     $expire = 3600 * 24;
     $requestTime = $_SERVER['REQUEST_TIME'];
     $lastModified = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) : 0;
     if ($lastModified && $requestTime <= $lastModified + $expire) {
         header('HTTP/1.1 304 Not Modified', true);
         $responseTime = $lastModified;
         $exit = true;
     } else {
         $responseTime = $requestTime;
         $exit = false;
     }
     header('Cache-Control: max-age=' . $expire);
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $responseTime) . ' GMT');
     header('Expires: ' . gmdate('D, d M Y H:i:s', $responseTime + $expire) . ' GMT');
     if ($exit) {
         exit;
     }
     include CORE_ROOT . 'Thumb.class.php';
     $path = $this->get_gpath($path);
     if (!is_readable($path)) {
         $path = DATA_PATH . 'tmp/nothumb.jpg';
     }
     $Thumb = new Thumb();
     $Thumb->create($path, $windth, $height);
     $Thumb->show();
 }
Exemplo n.º 5
0
 * 图片目录绝对路径 最后带 /
 */
define('iPHP_RES_PAHT', '/data/www/ooxx.com/res/');
/**
 * 缓存缩略图配置
 */
define('iPHP_RES_CACHE', false);
//是否开启缓存
define('iPHP_RES_CACHE_DIR', 'thumbCache');
//缓存目录名
define('iPHP_RES_CACHE_TIME', 2592000);
//缓存时间
define('THUMB_PATH', $_GET['fp']);
//原图地址
define('THUMB_WIDTH', (int) $_GET['w']);
//缩略图宽度
define('THUMB_HEIGHT', (int) $_GET['h']);
//缩略图高度
/**
 * 可用尺寸 开启缓存后建议填写
 * @var array
 */
$thumbSizeMap = array();
$thumbSize = THUMB_WIDTH . 'x' . THUMB_HEIGHT;
/**
 * 生成缩略图
 */
if (in_array($thumbSize, $thumbSizeMap) || empty($thumbSizeMap)) {
    Thumb::make(THUMB_PATH, THUMB_WIDTH, THUMB_HEIGHT);
    Thumb::create();
}
Exemplo n.º 6
0
    ?>

    <div class="project-element col-6 tablet fullwidth-rwd">
      <a href="<?php 
    echo Project::name2url($project['projectTitle']);
    ?>
" title="<?php 
    echo $project['projectTitle'];
    ?>
">
          <div class="amount_gallery"><?php 
    echo $project['photoCount'];
    ?>
</div>
          <div class="front-project" style="background-image: url('<?php 
    echo Thumb::create('data/' . $photo['photoName'], 600, 999);
    ?>
');">
            <!-- <img src="<?php 
    echo Template::src('data/' . $photo['photoName']);
    ?>
" alt="<?php 
    echo $photo['photoAlt'];
    ?>
"> -->
          </div>
          <div class="info-project tablet-hidden">
            <h3 class="title-element-project"><?php 
    echo $project['projectTitle'];
    ?>
</h3>