Пример #1
0
 public function ChangeImage()
 {
     Log::Debug("Changing resource image for resource id %s", $this->page->GetResourceId());
     $uploadedImage = $this->page->GetUploadedImage();
     if ($uploadedImage->IsError()) {
         die("Image error: " . $uploadedImage->Error());
     }
     $fileType = strtolower($uploadedImage->Extension());
     $supportedTypes = array('jpeg', 'gif', 'png', 'jpg');
     if (!in_array($fileType, $supportedTypes)) {
         die("Invalid image type: {$fileType}");
     }
     $image = $this->imageFactory->Load($uploadedImage->TemporaryName());
     $image->ResizeToWidth(300);
     $fileName = "resource{$this->page->GetResourceId()}.{$fileType}";
     $imageUploadDirectory = Configuration::Instance()->GetKey(ConfigKeys::IMAGE_UPLOAD_DIRECTORY);
     $path = '';
     if (is_dir($imageUploadDirectory)) {
         $path = $imageUploadDirectory;
     } else {
         if (is_dir(ROOT_DIR . $imageUploadDirectory)) {
             $path = ROOT_DIR . $imageUploadDirectory;
         }
     }
     $path = "{$path}/{$fileName}";
     Log::Debug("Saving resource image {$path}");
     $image->Save($path);
     $this->SaveResourceImage($fileName);
 }