示例#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 save()
 {
     ActiveRecord::beginTransaction();
     $image = null;
     try {
         $image = ActiveRecord::getInstanceById($this->getModelClass(), $this->request->get('imageId'), true);
         $multilingualFields = array("title");
         $image->setValueArrayByLang($multilingualFields, $this->application->getDefaultLanguageCode(), $this->application->getLanguageArray(true), $this->request);
         $image->save();
         if ($_FILES['image']['tmp_name']) {
             $resizer = new ImageManipulator($_FILES['image']['tmp_name']);
             if (!$resizer->isValidImage()) {
                 throw new InvalidImageException();
             }
             if (!$image->resizeImage($resizer)) {
                 throw new ImageResizeException();
             }
         }
     } catch (InvalidImageException $exc) {
         $error = $this->translate('_err_not_image');
     } catch (ImageResizeException $exc) {
         $error = $this->translate('_err_resize');
     } catch (Exception $exc) {
         $error = $this->translate('_err_not_found ' . get_class($exc));
     }
     $response = new ActionResponse();
     if (isset($error)) {
         ActiveRecord::rollback();
         $result = array('error' => $error);
     } else {
         ActiveRecord::commit();
         $result = $image->toArray();
     }
     $this->setLayout('iframeJs');
     $response->set('ownerId', $this->request->get('ownerId'));
     $response->set('imageId', $this->request->get('imageId'));
     $response->set('result', @json_encode($result));
     return $response;
 }
示例#3
0
 private function importImage(ProductImage $image, $path)
 {
     if (!$path) {
         return false;
     }
     if (@parse_url($path, PHP_URL_SCHEME)) {
         $fetch = new NetworkFetch($path);
         $path = $fetch->fetch() ? $fetch->getTmpFile() : '';
     } else {
         if (!file_exists($path)) {
             foreach (array('/tmp/import/', ClassLoader::getRealPath('public.import.')) as $loc) {
                 $p = $loc . $path;
                 if (file_exists($p)) {
                     $path = $p;
                     break;
                 }
             }
         }
         if (!file_exists($path)) {
             $path = '';
         }
     }
     if ($path) {
         $man = new ImageManipulator($path);
         if ($man->isValidImage()) {
             $image->save();
             $image->resizeImage($man);
             $image->save();
         }
     }
 }