/**
  * Converts the given string or array to a ResourcePointer object.
  *
  * If the input format is an array, this method assumes the resource to be a
  * fresh file upload and imports the temporary upload file through the
  * resource manager.
  *
  * @param array $source The upload info (expected keys: error, name, tmp_name)
  * @param string $targetType
  * @param array $convertedChildProperties
  * @param \TYPO3\FLOW3\Property\PropertyMappingConfigurationInterface $configuration
  * @return \TYPO3\Media\Domain\Model\Image An object or an instance of TYPO3\FLOW3\Error\Error if the input format is not supported or could not be converted for other reasons
  * @throws \TYPO3\FLOW3\Property\Exception\TypeConverterException
  */
 public function convertFrom($source, $targetType, array $convertedChildProperties = array(), \TYPO3\FLOW3\Property\PropertyMappingConfigurationInterface $configuration = NULL)
 {
     $resource = $this->resourceManager->importUploadedResource($_FILES['file']);
     if ($resource === FALSE) {
         throw new \TYPO3\FLOW3\Property\Exception\TypeConverterException('Resource could not be converted.', 1316428994);
     }
     $image = new \TYPO3\Media\Domain\Model\Image($resource);
     // TODO: this should maybe be settable
     $image->setTitle('');
     return $image;
 }
 /**
  * Replaces images (<img src="Foo.png">) by persistent resources (<img src="_Resources/....">)
  *
  * @param string $bodyText
  * @return string the text with replaced image tags
  */
 protected function replaceImages($bodyText)
 {
     $self = $this;
     $configuration = $this->bundleConfiguration;
     $resourceManager = $this->resourceManager;
     $resourcePublisher = $this->resourcePublisher;
     $bodyText = preg_replace_callback('/(<img .*?src=")([^"]*)(".*?\\/>)/', function ($matches) use($self, $configuration, $resourceManager, $resourcePublisher) {
         $imageRootPath = isset($configuration['imageRootPath']) ? $configuration['imageRootPath'] : \TYPO3\FLOW3\Utility\Files::concatenatePaths(array($configuration['renderedDocumentationRootPath'], '_images'));
         $imagePathAndFilename = \TYPO3\FLOW3\Utility\Files::concatenatePaths(array($imageRootPath, basename($matches[2])));
         $imageResource = $resourceManager->importResource($imagePathAndFilename);
         $image = new \TYPO3\Media\Domain\Model\Image($imageResource);
         if ($image->getWidth() > $configuration['imageMaxWidth'] || $image->getHeight() > $configuration['imageMaxHeight']) {
             $image = $image->getThumbnail($configuration['imageMaxWidth'], $configuration['imageMaxHeight']);
         }
         $imageUri = '_Resources/' . $resourcePublisher->publishPersistentResource($image->getResource());
         if ($image->getWidth() > $configuration['thumbnailMaxWidth'] || $image->getHeight() > $configuration['thumbnailMaxHeight']) {
             $thumbnail = $image->getThumbnail(710, 800);
             $thumbnailUri = '_Resources/' . $resourcePublisher->getPersistentResourceWebUri($thumbnail->getResource());
             return sprintf('<a href="%s" class="lightbox">%s%s" style="width: %dpx" /></a>', $imageUri, $matches[1], $thumbnailUri, $thumbnail->getWidth());
         } else {
             return sprintf('%s%s" style="width: %dpx" />', $matches[1], $imageUri, $image->getWidth());
         }
     }, $bodyText);
     return $bodyText;
 }