예제 #1
0
파일: ThemeFile.php 프로젝트: saiber/www
 private function createThumbnail($fileName)
 {
     $im = new ImageManipulator($this->path . $fileName);
     if ($im->isValidImage()) {
         $size = $this->getThumbnailSize();
         $res = $im->resize($size[0], $size[1], $this->thumbnailPath . $fileName);
         return $res;
     }
     return false;
 }
예제 #2
0
 public function resizeImage(ImageManipulator $resizer)
 {
     foreach ($this->getImageSizes() as $key => $size) {
         $filePath = $this->getPath($key);
         if (!file_exists(dirname($filePath))) {
             mkdir(dirname($filePath), 0777, true);
         }
         $res = $resizer->resize($size[0], $size[1], $filePath);
         if (!$res) {
             break;
         }
     }
     return $res;
 }
예제 #3
0
 public function uploadProductImage()
 {
     ClassLoader::import('application.model.product.ProductImage');
     ClassLoader::import('library.image.ImageManipulator');
     $field = 'upload_' . $this->request->get('field');
     $dir = ClassLoader::getRealPath('public.upload.tmpimage.');
     // delete old tmp files
     chdir($dir);
     $dh = opendir($dir);
     $threshold = strtotime("-1 day");
     while (($dirent = readdir($dh)) != false) {
         if (is_file($dirent)) {
             if (filemtime($dirent) < $threshold) {
                 unlink($dirent);
             }
         }
     }
     closedir($dh);
     // create tmp file
     $file = $_FILES[$field];
     $tmp = 'tmp_' . $field . md5($file['tmp_name']) . '__' . $file['name'];
     if (!file_exists($dir)) {
         mkdir($dir, 0777, true);
         chmod($dir, 0777);
     }
     $path = $dir . $tmp;
     move_uploaded_file($file['tmp_name'], $path);
     if (@getimagesize($path)) {
         $thumb = 'tmp_thumb_' . $tmp;
         $thumbPath = $dir . $thumb;
         $thumbDir = dirname($thumbPath);
         if (!file_exists($thumbDir)) {
             mkdir($thumbDir, 0777, true);
             chmod($thumbDir, 0777);
         }
         $conf = self::getApplication()->getConfig();
         $img = new ImageManipulator($path);
         $thumbSize = ProductImage::getImageSizes();
         $thumbSize = $thumbSize[2];
         // 1 is too small, cant see a thing.
         $img->resize($thumbSize[0], $thumbSize[1], $thumbPath);
         $thumb = 'upload/tmpimage/' . $thumb;
     } else {
         return new JSONResponse(null, 'failure', $this->translate('_error_uploading_image'));
     }
     return new JSONResponse(array('name' => $file['name'], 'file' => $tmp, 'thumb' => $thumb), 'success');
 }
예제 #4
0
 public function resizeImage($source, $target, $confSuffix)
 {
     $dir = dirname($target);
     if (!file_exists($dir)) {
         mkdir($dir, 0777);
         chmod($dir, 0777);
     }
     $conf = self::getApplication()->getConfig();
     $img = new ImageManipulator($source);
     $img->setQuality($conf->get('IMG_O_Q_' . $confSuffix));
     $img->resize($conf->get('IMG_O_W_' . $confSuffix), $conf->get('IMG_O_H_' . $confSuffix), $target);
 }