コード例 #1
0
ファイル: Image.php プロジェクト: gravitymedia/magickly
 /**
  * {@inheritdoc}
  */
 public function getFormat()
 {
     $format = $this->gmagick->getimageformat();
     if (!in_array($format, static::$supportedFormats)) {
         throw new RuntimeException('Unsupported image format');
     }
     return $format;
 }
コード例 #2
0
ファイル: BaseElement.php プロジェクト: xav335/sfnettoyage
 /**
  * @final
  * @global array $motopressCESettings
  * @global MPCERequirements $motopressCERequirements
  * @global stdClass $motopressCELang
  * @param string $icon
  * @param string $iconDir
  */
 protected final function icon($icon, $iconDir)
 {
     global $motopressCESettings;
     global $motopressCERequirements;
     global $motopressCELang;
     if (is_string($icon)) {
         $icon = trim($icon);
         if (!empty($icon)) {
             $icon = filter_var($icon, FILTER_SANITIZE_STRING);
             if (dirname($icon) === '.') {
                 $iconPath = $motopressCESettings['plugin_root'] . '/' . $motopressCESettings['plugin_name'] . '/images/ce/' . $iconDir . '/' . $icon;
                 $iconUrl = $motopressCESettings['plugin_root_url'] . '/' . $motopressCESettings['plugin_name'] . '/images/ce/' . $iconDir . '/' . $icon;
             } else {
                 $iconPath = WP_CONTENT_DIR . '/' . $icon;
                 $iconUrl = WP_CONTENT_URL . '/' . $icon;
             }
             $iconUrl .= '?ver=' . $motopressCESettings['plugin_version'];
             if (file_exists($iconPath)) {
                 $mimeType = null;
                 if ($motopressCERequirements->getGd()) {
                     $info = getimagesize($iconPath);
                     if ($info) {
                         $mimeType = $info['mime'];
                     }
                 }
                 if (is_null($mimeType) && $motopressCERequirements->getFileinfo() && version_compare(PHP_VERSION, '5.3.0', '>=')) {
                     $finfo = new finfo(FILEINFO_MIME_TYPE);
                     $finfoMimeType = $finfo->file($iconPath);
                     if ($finfoMimeType) {
                         $mimeType = $finfoMimeType;
                     }
                 }
                 if (is_null($mimeType) && $motopressCERequirements->getExif()) {
                     $exifImageType = exif_imagetype($iconPath);
                     if ($exifImageType) {
                         $mimeType = image_type_to_mime_type($exifImageType);
                     }
                 }
                 $extension = null;
                 if (is_null($mimeType) && $motopressCERequirements->getImagick()) {
                     try {
                         $imagick = new Imagick($iconPath);
                         $extension = strtolower($imagick->getImageFormat());
                     } catch (ImagickException $e) {
                         if ($motopressCESettings['debug']) {
                             var_dump($e);
                         }
                     }
                 }
                 if (is_null($extension) && $motopressCERequirements->getGmagick()) {
                     try {
                         $gmagick = new Gmagick($iconPath);
                         $extension = strtolower($gmagick->getimageformat());
                     } catch (GmagickException $e) {
                         if ($motopressCESettings['debug']) {
                             var_dump($e);
                         }
                     }
                 }
                 if (is_null($extension)) {
                     $extension = pathinfo($iconPath, PATHINFO_EXTENSION);
                 }
                 if (!is_null($mimeType) || !is_null($extension)) {
                     if (in_array($mimeType, self::$mimeTypes) || in_array($extension, self::$extensions)) {
                         $this->icon = $iconUrl;
                     } else {
                         $this->addError('icon', strtr($motopressCELang->CEIconValidation, array('%name%' => $mimeType)));
                     }
                 } else {
                     $this->addError('icon', $motopressCELang->CEUnknownMimeType);
                 }
             } else {
                 $this->addError('icon', strtr($motopressCELang->fileNotExists, array('%name%' => $iconPath)));
             }
         } else {
             $this->addError('icon', $motopressCELang->CEEmpty);
         }
     } else {
         $this->addError('icon', strtr($motopressCELang->CEInvalidArgumentType, array('%name%' => gettype($icon))));
     }
 }