Esempio n. 1
0
 protected function _resizeSaveUploadedImage($fileId, Sitengine_Upload $upload, $id)
 {
     require_once 'Sitengine/Mime/Type.php';
     $suffix = preg_replace('/.*\\.(\\w+)$/', "\$1", $upload->getName());
     if ($upload->getName() == $suffix) {
         # there is no suffix in the filename
         require_once 'Sitengine/Exception.php';
         throw new Sitengine_Exception('file needs to have a valid suffix');
     }
     $suffix = '.' . $suffix;
     $name = $this->makeFileName($fileId, $id, $suffix);
     $mime = Sitengine_Mime_Type::get($suffix);
     try {
         if (Sitengine_Mime_Type::isJpg($mime)) {
             require_once 'Sitengine/Image.php';
             $data = Sitengine_Image::resizeJpeg($upload->getTempName(), $this->_configs[$fileId]['tempDir'] . '/' . $name, $this->_configs[$fileId]['length'], $this->_configs[$fileId]['method'], $this->_configs[$fileId]['mode'], $this->_configs[$fileId]['jpgQuality']);
             #$this->_newFiles[$fileId] = $name;
             $data['name'] = $name;
             $data['source'] = $upload->getName();
             $this->_files[$fileId] = $data;
         } else {
             if (Sitengine_Mime_Type::isGif($mime)) {
                 require_once 'Sitengine/Image.php';
                 $data = Sitengine_Image::resizeGif($upload->getTempName(), $this->_configs[$fileId]['tempDir'] . '/' . $name, $this->_configs[$fileId]['length'], $this->_configs[$fileId]['method'], $this->_configs[$fileId]['mode'], $this->_configs[$fileId]['transColor']);
                 #$this->_newFiles[$fileId] = $name;
                 $data['name'] = $name;
                 $data['source'] = $upload->getName();
                 $this->_files[$fileId] = $data;
             } else {
                 if (Sitengine_Mime_Type::isPng($mime)) {
                     require_once 'Sitengine/Image.php';
                     $data = Sitengine_Image::resizePng($upload->getTempName(), $this->_configs[$fileId]['tempDir'] . '/' . $name, $this->_configs[$fileId]['length'], $this->_configs[$fileId]['method'], $this->_configs[$fileId]['mode'], $this->_configs[$fileId]['transColor']);
                     #$this->_newFiles[$fileId] = $name;
                     $data['name'] = $name;
                     $data['source'] = $upload->getName();
                     $this->_files[$fileId] = $data;
                 }
             }
         }
         if (Sitengine_Mime_Type::isJpg($mime) || Sitengine_Mime_Type::isGif($mime) || Sitengine_Mime_Type::isPng($mime)) {
             #$key = $this->_configs[$fileId]['prefix'].'/'.$name;
             #$object = $this->_configs[$fileId]['object'];
             require_once 'Sitengine/Amazon/S3/Object.php';
             $object = new Sitengine_Amazon_S3_Object($this->_configs[$fileId]['connection'], $this->_configs[$fileId]['bucket'], $this->_configs[$fileId]['prefix'] . '/' . $name, $this->_configs[$fileId]['cname'], $this->_configs[$fileId]['ssl']);
             $amzHeaders = $this->_configs[$fileId]['amzHeaders'];
             $response = $object->put($this->_configs[$fileId]['tempDir'] . '/' . $name, array(), $amzHeaders);
             if ($response->getHttpResponse()->isError()) {
                 require_once 'Sitengine/Exception.php';
                 throw new Sitengine_Exception('file could not be uploaded to s3');
             }
             $this->_newFiles[$fileId] = $name;
             unlink($this->_configs[$fileId]['tempDir'] . '/' . $name);
         }
     } catch (Exception $exception) {
         $this->_rollback();
         require_once 'Sitengine/Exception.php';
         throw new Sitengine_Exception('resize upload uploaded s3 image failed', $exception);
     }
 }
Esempio n. 2
0
 protected function _resizeSaveImportedImage($fileId, $sourcePath, $id)
 {
     $suffix = '.' . preg_replace('/.*\\.(\\w+)$/', "\$1", $sourcePath);
     $name = $this->makeFileName($fileId, $id, $suffix);
     $mime = Sitengine_Mime_Type::get($sourcePath);
     try {
         if (Sitengine_Mime_Type::isJpg($mime)) {
             $data = Sitengine_Image::resizeJpeg($sourcePath, $this->_configs[$fileId]['dir'] . '/' . $name, $this->_configs[$fileId]['length'], $this->_configs[$fileId]['method'], $this->_configs[$fileId]['mode'], $this->_configs[$fileId]['jpgQuality']);
             $this->_newFiles[$fileId] = $name;
             $data['name'] = $name;
             $data['source'] = basename($sourcePath);
             $this->_files[$fileId] = $data;
         } else {
             if (Sitengine_Mime_Type::isGif($mime)) {
                 $data = Sitengine_Image::resizeGif($sourcePath, $this->_configs[$fileId]['dir'] . '/' . $name, $this->_configs[$fileId]['length'], $this->_configs[$fileId]['method'], $this->_configs[$fileId]['mode'], $this->_configs[$fileId]['transColor']);
                 $this->_newFiles[$fileId] = $name;
                 $data['name'] = $name;
                 $data['source'] = basename($sourcePath);
                 $this->_files[$fileId] = $data;
             } else {
                 if (Sitengine_Mime_Type::isPng($mime)) {
                     $data = Sitengine_Image::resizePng($sourcePath, $this->_configs[$fileId]['dir'] . '/' . $name, $this->_configs[$fileId]['length'], $this->_configs[$fileId]['method'], $this->_configs[$fileId]['mode'], $this->_configs[$fileId]['transColor']);
                     $this->_newFiles[$fileId] = $name;
                     $data['name'] = $name;
                     $data['source'] = basename($sourcePath);
                     $this->_files[$fileId] = $data;
                 }
             }
         }
     } catch (Exception $exception) {
         $this->_rollbackFileImport();
         throw new Sitengine_Exception('resize save imported image failed', $exception);
     }
 }