protected static function processImageFile($inputFile, $loaderInfo)
 {
     // if no gd support, do nothing
     if (!function_exists('gd_info')) {
         return false;
     }
     // if there is only url and processMethod, do nothing
     if (count($loaderInfo) == 2) {
         return false;
     }
     // make inputFile as temprary file
     $outputFile = $inputFile;
     $processor = new ImageProcessor($inputFile);
     $transformer = new ImageTransformer($loaderInfo);
     //maintain original image type
     $imageType = null;
     $processor->transform($transformer, $imageType, $outputFile);
 }
 private function uploadFile($type, $section, $subsection, $key, $value)
 {
     $sectionData = $this->getAdminData($type, $section, $subsection);
     if (isset($value['error']) && $value['error'] != UPLOAD_ERR_OK) {
         throw new KurogoDataException(Kurogo::file_upload_error_message($value['error']));
     }
     if (!isset($value['tmp_name']) || !is_uploaded_file($value['tmp_name'])) {
         throw new KurogoDataException("Error locating uploaded file");
     }
     switch ($sectionData['sectiontype']) {
         case 'fields':
             if (!isset($sectionData['fields'][$key])) {
                 throw new KurogoConfigurationException("Invalid key {$key} for {$type} section {$section}");
             }
             $fieldData = $sectionData['fields'][$key];
             break;
         case 'section':
             $fieldData = $sectionData;
             throw new KurogoConfigurationException("Code not written for this type of field");
             break;
         default:
             throw new KurogoConfigurationException("Unable to handle {$type} {$section}. Invalid section type " . $sectionData['sectiontype']);
     }
     if (!isset($fieldData['destinationType'])) {
         throw new KurogoConfigurationException("Unable to determine destination type");
     }
     switch ($fieldData['destinationType']) {
         case 'file':
             if (!isset($fieldData['destinationFile'])) {
                 throw new KurogoConfigurationException("Unable to determine destination location");
             }
             $destination = $fieldData['destinationFile'];
             break;
         case 'folder':
             if (!isset($fieldData['destinationFile'])) {
                 throw new KurogoConfigurationException("Unable to determine destination location");
             }
             if (!isset($fieldData['destinationFolder'])) {
                 throw new KurogoConfigurationException("Unable to determine destination location");
             }
             $destination = rtrim($fieldData['destinationFolder'], '/') . '/' . ltrim($fieldData['destinationFile'], '/');
             break;
     }
     $prefix = isset($fieldData['destinationPrefix']) ? $fieldData['destinationPrefix'] : '';
     if ($prefix && defined($prefix)) {
         $destination = constant($prefix) . '/' . $destination;
     }
     if (isset($fieldData['fileType'])) {
         switch ($fieldData['fileType']) {
             case 'image':
                 $this->setResponseVersion(1);
                 try {
                     $imageData = new ImageProcessor($value['tmp_name']);
                     $transformer = new ImageTransformer($fieldData);
                     $imageType = isset($fieldData['imageType']) ? $fieldData['imageType'] : null;
                     $result = $imageData->transform($transformer, $imageType, $destination);
                     if (KurogoError::isError($result)) {
                         $this->throwError($result);
                     }
                 } catch (KurogoException $e) {
                     throw new KurogoException("Uploaded file must be a valid image (" . $e->getMessage() . ")");
                 }
                 break;
             default:
                 throw new KurogoConfigurationException("Unknown fileType " . $fieldData['fileType']);
         }
     } else {
         if (!move_uploaded_file($value['tmp_name'], $destination)) {
             $this->throwError(new KurogoError(1, "Cannot save file", "Unable to save uploaded file"));
         }
     }
 }