/**
  * Returns a widget type’s SVG icon.
  *
  * @param IWidget $widgetType
  *
  * @return string
  */
 private function _getWidgetIconSvg(IWidget $widgetType)
 {
     $iconPath = $widgetType->getIconPath();
     if ($iconPath && IOHelper::fileExists($iconPath) && FileHelper::getMimeType($iconPath) == 'image/svg+xml') {
         return IOHelper::getFileContents($iconPath);
     }
     return craft()->templates->render('_includes/defaulticon.svg', array('label' => $widgetType->getName()));
 }
 /**
  * If the path points to a real file, we call {@link FileHelper::getMimeType()}, otherwise
  * {@link FileHelper::getMimeTypeByExtension()}
  *
  * @param string $path The path to test.
  *
  * @return string The mime type.
  */
 public static function getMimeType($path)
 {
     if (@file_exists($path)) {
         return FileHelper::getMimeType($path);
     } else {
         return FileHelper::getMimeTypeByExtension($path);
     }
 }
Beispiel #3
0
 /**
  * Loads an image from a file system path.
  *
  * @param string $path
  *
  * @throws Exception
  * @return Image
  */
 public function loadImage($path)
 {
     if (!IOHelper::fileExists($path)) {
         throw new Exception(Craft::t('No file exists at the path “{path}”', array('path' => $path)));
     }
     if (!craft()->images->checkMemoryForImage($path)) {
         throw new Exception(Craft::t("Not enough memory available to perform this image operation."));
     }
     // Make sure the image says it's an image
     $mimeType = FileHelper::getMimeType($path, null, false);
     if ($mimeType !== null && strncmp($mimeType, 'image/', 6) !== 0) {
         throw new Exception(Craft::t('The file “{path}” does not appear to be an image.', array('path' => $path)));
     }
     try {
         $this->_image = $this->_instance->open($path);
     } catch (\Exception $exception) {
         throw new Exception(Craft::t('The file “{path}” does not appear to be an image.', array('path' => $path)));
     }
     // If we're using Imagick _and_ one that supports it, convert CMYK to RGB, save and re-open.
     if (!craft()->images->isGd() && $this->_image->getImagick()->getImageColorspace() == \Imagick::COLORSPACE_CMYK && method_exists($this->_image->getImagick(), 'transformimagecolorspace')) {
         $this->_image->getImagick()->transformimagecolorspace(\Imagick::COLORSPACE_SRGB);
         $this->_image->save();
         return craft()->images->loadImage($path);
     }
     $this->_imageSourcePath = $path;
     $this->_extension = IOHelper::getExtension($path);
     if ($this->_extension == 'gif') {
         if (!craft()->images->isGd() && $this->_image->layers()) {
             $this->_isAnimatedGif = true;
         }
     }
     $this->_resizeHeight = $this->getHeight();
     $this->_resizeWidth = $this->getWidth();
     return $this;
 }
Beispiel #4
0
 public function testDetectsCorrectMimeTypeUsingMagicNumbersAndFallingBackToExtensionLookupForSwf()
 {
     $pathToFile = dirname(__FILE__) . '/../../../../../resources/test.swf';
     $this->assertEquals('application/x-shockwave-flash', FileHelper::getMimeType($pathToFile));
 }