[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/marc1706/fast-image-size/lib/Type/ -> TypeWbmp.php (source)

   1  <?php
   2  
   3  /**
   4   * fast-image-size image type wbmp
   5   * @package fast-image-size
   6   * @copyright (c) Marc Alexander <admin@m-a-styles.de>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace FastImageSize\Type;
  13  
  14  class TypeWbmp extends TypeBase
  15  {
  16      /**
  17       * {@inheritdoc}
  18       */
  19  	public function getSize($filename)
  20      {
  21          $data = $this->fastImageSize->getImage($filename, 0, self::LONG_SIZE);
  22  
  23          // Check if image is WBMP
  24          if ($data === false || !$this->validWBMP($data))
  25          {
  26              return;
  27          }
  28  
  29          $size = unpack('Cwidth/Cheight', substr($data, self::SHORT_SIZE, self::SHORT_SIZE));
  30  
  31          // Check if dimensions are valid. A file might be recognised as WBMP
  32          // rather easily (see extra check for JPEG2000).
  33          if (!$this->validDimensions($size))
  34          {
  35              return;
  36          }
  37  
  38          $this->fastImageSize->setSize($size);
  39          $this->fastImageSize->setImageType(IMAGETYPE_WBMP);
  40      }
  41  
  42      /**
  43       * Return if supplied data might be part of a valid WBMP file
  44       *
  45       * @param bool|string $data
  46       *
  47       * @return bool True if data might be part of a valid WBMP file, else false
  48       */
  49  	protected function validWBMP($data)
  50      {
  51          return ord($data[0]) === 0 && ord($data[1]) === 0 && $data !== substr(TypeJp2::JPEG_2000_SIGNATURE, 0, self::LONG_SIZE);
  52      }
  53  
  54      /**
  55       * Return whether dimensions are valid
  56       *
  57       * @param array $size Size array
  58       *
  59       * @return bool True if dimensions are valid, false if not
  60       */
  61  	protected function validDimensions($size)
  62      {
  63          return $size['height'] > 0 && $size['width'] > 0;
  64      }
  65  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1