<commit_before><?php

/*
 * This file is part of MediaVorus.
 *
 * (c) 2012 <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace MediaVorus\Media;

use \MediaVorus\Utils\RawImageMimeTypeGuesser;

/**
 *
 * @author      <NAME> - <EMAIL>
 * @license     http://opensource.org/licenses/MIT MIT
 *
 * @todo refactor Meta resolver to an independant object
 */
class Image extends DefaultMedia
{
    /**
     * Orientation constant Horizontal (normal)
     */
    const ORIENTATION_0 = 0;
    /**
     * Orientation constant Vertical (90 CW)
     */
    const ORIENTATION_90 = 90;
    /**
     * Orientation constant Vertical (270 CW)
     */
    const ORIENTATION_270 = 270;
    /**
     * Orientation constant Horizontal (reversed)
     */
    const ORIENTATION_180 = 180;
    /**
     * Colorspace constant CMYK
     */
    const COLORSPACE_CMYK = 'CMYK';
    /**
     * Colorspace constant RGB
     */
    const COLORSPACE_RGB = 'RGB';
    /**
     * Colorspace constant sRGB
     */
    const COLORSPACE_SRGB = 'sRGB';
    /**
     * Colorspace constant Grayscale
     */
    const COLORSPACE_GRAYSCALE = 'Grayscale';

    /**
     *
     * @return string
     */
    public function getType()
    {
        return self::TYPE_IMAGE;
    }

    /**
     * Returns true if the document is a "Raw" image
     *
     * @return boolean
     */
    public function isRawImage()
    {
        return in_array($this->getFile()->getMimeType(), RawImageMimeTypeGuesser::$rawMimeTypes);
    }

    /**
     * Returns true if the document has multiple layers.
     * This method is supposed to be used to extract layer 0 with ImageMagick
     *
     * @return type
     */
    public function hasMultipleLayers()
    {
        return in_array($this->getFile()->getMimeType(), array(
                'image/tiff',
                'application/pdf',
                'image/psd',
                'image/vnd.adobe.photoshop',
                'image/photoshop',
                'image/ai',
                'image/illustrator',
                'image/vnd.adobe.illustrator'
            ));
    }

    /**
     * Return the width, null on error
     *
     * @return int
     */
    public function getWidth()
    {
        if ($this->getMetadatas()->containsKey('File:ImageWidth')) {
            return (int) $this->getMetadatas()->get('File:ImageWidth')->getValue()->asString();
        }

        if ($this->getMetadatas()->containsKey('Composite:ImageSize')) {
            $dimensions = $this->extractFromDimensions(
                $this->getMetadatas()->get('Composite:ImageSize')->getValue()->asString()
            );

            if ($dimensions) {
                return (int) $dimensions['width'];
            }
        }

        $sources = array('SubIFD:ImageWidth', 'IFD0:ImageWidth', 'ExifIFD:ExifImageWidth');

        return $this->castValue($this->findInSources($sources), 'int');
        }

    /**
     * Return the height, null on error
     *
     * @return int
     */
    public function getHeight()
    {
        if ($this->getMetadatas()->containsKey('File:ImageHeight')) {
            return (int) $this->getMetadatas()->get('File:ImageHeight')->getValue()->asString();
        }

        if ($this->getMetadatas()->containsKey('Composite:ImageSize')) {
            $dimensions = $this->extractFromDimensions(
                $this->getMetadatas()->get('Composite:ImageSize')->getValue()->asString()
            );

            if ($dimensions) {
                return (int) $dimensions['height'];
            }
        }

        $sources = array('SubIFD:ImageHeight', 'IFD0:ImageHeight', 'ExifIFD:ExifImageHeight');

        return $this->castValue($this->findInSources($sources), 'int');
    }
<commit_msg>Fix CS<commit_after><?php

/*
 * This file is part of MediaVorus.
 *
 * (c) 2012 <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace MediaVorus\Media;

use \MediaVorus\Utils\RawImageMimeTypeGuesser;

/**
 *
 * @author      <NAME> - <EMAIL>
 * @license     http://opensource.org/licenses/MIT MIT
 *
 * @todo refactor Meta resolver to an independant object
 */
class Image extends DefaultMedia
{
    /**
     * Orientation constant Horizontal (normal)
     */
    const ORIENTATION_0 = 0;
    /**
     * Orientation constant Vertical (90 CW)
     */
    const ORIENTATION_90 = 90;
    /**
     * Orientation constant Vertical (270 CW)
     */
    const ORIENTATION_270 = 270;
    /**
     * Orientation constant Horizontal (reversed)
     */
    const ORIENTATION_180 = 180;
    /**
     * Colorspace constant CMYK
     */
    const COLORSPACE_CMYK = 'CMYK';
    /**
     * Colorspace constant RGB
     */
    const COLORSPACE_RGB = 'RGB';
    /**
     * Colorspace constant sRGB
     */
    const COLORSPACE_SRGB = 'sRGB';
    /**
     * Colorspace constant Grayscale
     */
    const COLORSPACE_GRAYSCALE = 'Grayscale';

    /**
     *
     * @return string
     */
    public function getType()
    {
        return self::TYPE_IMAGE;
    }

    /**
     * Returns true if the document is a "Raw" image
     *
     * @return boolean
     */
    public function isRawImage()
    {
        return in_array($this->getFile()->getMimeType(), RawImageMimeTypeGuesser::$rawMimeTypes);
    }

    /**
     * Returns true if the document has multiple layers.
     * This method is supposed to be used to extract layer 0 with ImageMagick
     *
     * @return type
     */
    public function hasMultipleLayers()
    {
        return in_array($this->getFile()->getMimeType(), array(
                'image/tiff',
                'application/pdf',
                'image/psd',
                'image/vnd.adobe.photoshop',
                'image/photoshop',
                'image/ai',
                'image/illustrator',
                'image/vnd.adobe.illustrator'
            ));
    }

    /**
     * Return the width, null on error
     *
     * @return int
     */
    public function getWidth()
    {
        if ($this->getMetadatas()->containsKey('File:ImageWidth')) {
            return (int) $this->getMetadatas()->get('File:ImageWidth')->getValue()->asString();
        }

        if ($this->getMetadatas()->containsKey('Composite:ImageSize')) {
            $dimensions = $this->extractFromDimensions(
                $this->getMetadatas()->get('Composite:ImageSize')->getValue()->asString()
            );

            if ($dimensions) {
                return (int) $dimensions['width'];
            }
        }

        $sources = array('SubIFD:ImageWidth', 'IFD0:ImageWidth', 'ExifIFD:ExifImageWidth');

        return $this->castValue($this->findInSources($sources), 'int');
    }

    /**
     * Return the height, null on error
     *
     * @return int
     */
    public function getHeight()
    {
        if ($this->getMetadatas()->containsKey('File:ImageHeight')) {
            return (int) $this->getMetadatas()->get('File:ImageHeight')->getValue()->asString();
        }

        if ($this->getMetadatas()->containsKey('Composite:ImageSize')) {
            $dimensions = $this->extractFromDimensions(
                $this->getMetadatas()->get('Composite:ImageSize')->getValue()->asString()
            );

            if ($dimensions) {
                return (int) $dimensions['height'];
            }
        }

        $sources = array('SubIFD:ImageHeight', 'IFD0:ImageHeight', 'ExifIFD:ExifImageHeight');

        return $this->castValue($this->findInSources($sources), 'int');
    }

{'fraction_non_alphanumeric': 0.13872529773589845, 'fraction_numerical': 0.007852375343541421, 'mean_word_length': 2.093927125506073, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6487556', 'n_tokens_mistral': 2368, 'n_tokens_neox': 2231, 'n_words': 467}