Ejemplo n.º 1
0
 /**
  * (non-PHPdoc)
  * @see Bgtask_Abstract::run()
  */
 public function run()
 {
     $mediaModel = Model::factory('Medialib');
     $types = $this->_config['types'];
     $nonCroped = $this->_config['notCroped'];
     $docRoot = Registry::get('main', 'config')->get('docroot');
     $filter = array('type' => 'image');
     if ($nonCroped) {
         $filter['croped'] = 0;
     }
     $data = $mediaModel->getListVc(false, $filter, false, array('path', 'ext', 'croped'));
     if (empty($data)) {
         $this->_finish();
     }
     $conf = $mediaModel->getConfig()->__toArray();
     $thumbSizes = $conf['image']['sizes'];
     if (!$types || !is_array($types)) {
         return;
     }
     $this->setTotalCount(sizeof($data));
     foreach ($data as $v) {
         // sub dir fix
         if ($v['path'][0] !== '/') {
             $v['path'] = '/' . $v['path'];
         }
         $path = $docRoot . $v['path'];
         if (!file_exists($path)) {
             $this->log('Skip  non existent file: ' . $path);
             continue;
         }
         foreach ($types as $typename) {
             if (!isset($thumbSizes[$typename])) {
                 continue;
             }
             $saveName = str_replace($v['ext'], '-' . $typename . $v['ext'], $path);
             if ($conf['image']['thumb_types'][$typename] == 'crop') {
                 Image_Resize::resize($path, $thumbSizes[$typename][0], $thumbSizes[$typename][1], $saveName, true, true);
             } else {
                 Image_Resize::resize($path, $thumbSizes[$typename][0], $thumbSizes[$typename][1], $saveName, true, false);
             }
         }
         /*
          * Update task status and check for signals 
          */
         $this->incrementCompleted();
         $this->updateState();
         $this->processSignals();
     }
     $this->finish();
 }
Ejemplo n.º 2
0
 /**
  * (non-PHPdoc)
  * @see Upload_File::upload()
  */
 public function upload(array $data, $path, $formUpload = true)
 {
     $data = parent::upload($data, $path, $formUpload);
     if (!empty($data) && !empty($this->_config['sizes'])) {
         foreach ($this->_config['sizes'] as $name => $xy) {
             $ext = File::getExt($data['path']);
             $replace = '-' . $name . $ext;
             $newName = str_replace($ext, $replace, $data['path']);
             if ($this->_config['thumb_types'][$name] == 'crop') {
                 Image_Resize::resize($data['path'], $xy[0], $xy[1], $newName, true, true);
             } else {
                 Image_Resize::resize($data['path'], $xy[0], $xy[1], $newName, true, false);
             }
             if ($name == 'icon') {
                 $data['thumb'] = $newName;
             }
         }
     }
     return $data;
 }
Ejemplo n.º 3
0
 /**
  * Crop image and create thumbs
  * @param array $srcData  - media library record
  * @param integer $x
  * @param integer $y
  * @param integer $w
  * @param integer $h
  */
 public function cropAndResize($srcData, $x, $y, $w, $h, $type)
 {
     $appConfig = Registry::get('main', 'config');
     ini_set('max_execution_time', 18000);
     ini_set('memory_limit', '384M');
     $docRoot = $appConfig['docroot'];
     $conf = $this->getConfig()->__toArray();
     $thumbSizes = $conf['image']['sizes'];
     // sub dir fix
     if ($srcData['path'][0] !== '/') {
         $srcData['path'] = '/' . $srcData['path'];
     }
     $path = $docRoot . $srcData['path'];
     if (!file_exists($path)) {
         false;
     }
     $tmpPath = $appConfig['tmp'] . basename($path);
     Image_Resize::cropImage($path, $tmpPath, $x, $y, $w, $h);
     if (!isset($thumbSizes[$type])) {
         return false;
     }
     $saveName = str_replace($srcData['ext'], '-' . $type . $srcData['ext'], $path);
     if (!Image_Resize::resize($tmpPath, $thumbSizes[$type][0], $thumbSizes[$type][1], $saveName, true, false)) {
         return false;
     }
     unlink($tmpPath);
     return true;
 }
Ejemplo n.º 4
0
<?php

require_once '../../www/system/library/Image/Resize.php';
$images = array('1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg');
$sizes = array(array(300, 100), array(300, 250), array(400, 100), array(400, 350), array(200, 200), array(100, 300));
foreach ($images as $image) {
    foreach ($sizes as $k => $config) {
        Image_Resize::resize('./src/' . $image, $config[0], $config[1], './thumbs/crop_' . $image . '_' . $config[0] . 'x' . $config[1] . '.jpg', false, true);
    }
}
foreach ($images as $image) {
    foreach ($sizes as $k => $config) {
        Image_Resize::resize('./src/' . $image, $config[0], $config[1], './thumbs/simple_' . $image . '_' . $config[0] . 'x' . $config[1] . '.jpg', false, false);
    }
}
foreach ($images as $image) {
    foreach ($sizes as $k => $config) {
        Image_Resize::resize('./src/' . $image, $config[0], $config[1], './thumbs/simple_fit_' . $image . '_' . $config[0] . 'x' . $config[1] . '.jpg', true, false);
    }
}