public function Format($row, $fieldname, $value)
 {
     $files = $this->_context->getUploadFileNames();
     if ($files[$fieldname] != "") {
         $fileProcessor = new UploadFilenameProcessor($this->_saveAs);
         $fileProcessor->setFilenameLocation(ForceFilenameLocation::DefinePath, FileUtil::GetTempDir());
         // Save the files in a temporary directory
         $result = $this->_context->processUpload($fileProcessor, false, $fieldname);
         // Get a way to rename the files
         $fileinfo = pathinfo($result[0]);
         if ($this->_saveAs != "*") {
             $path_parts = pathinfo($this->_saveAs);
         } else {
             $path_parts = pathinfo($result[0]);
         }
         $newName = $this->_path . FileUtil::Slash() . $path_parts['filename'] . "." . $fileinfo["extension"];
         // Put the image in the right place
         if (strpos(".jpg.gif.jpeg.png", "." . $fileinfo["extension"]) === false) {
             rename($result[0], $newName);
         } else {
             if ($this->_width > 0 || $this->_height > 0) {
                 $image = new ImageUtil($result[0]);
                 $image->resizeAspectRatio($this->_width, $this->_height, 255, 255, 255)->save($newName);
             } else {
                 rename($result[0], $newName);
             }
         }
         return $newName;
     } else {
         return $row->getField($fieldname);
     }
 }
Beispiel #2
0
 /**
  * @covers ByJG\ImageUtil\ImageUtil::resizeAspectRatio
  */
 public function testResizeAspectRatio()
 {
     $image = new ImageUtil(__DIR__ . '/resize_aspectratio.bmp');
     $this->object->resizeAspectRatio(400, 200, 255, 0, 0);
     $this->assertEquals($this->getResourceString($image->getImage()), $this->getResourceString($this->object->getImage()));
 }