Issues (45)

src/Models/Media/Image.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * This file is part of the Divergence package.
4
 *
5
 * (c) Henry Paradiz <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Divergence\Models\Media;
12
13
use Exception;
14
15
/**
16
 * Image Media Model
17
 *
18
 * @author Henry Paradiz <[email protected]>
19
 * @author Chris Alfano <[email protected]>
20
 *
21
 * {@inheritDoc}
22
 */
23
class Image extends Media
0 ignored issues
show
The type Divergence\Models\Media\Media was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
{
25
    // configurables
26
    public static $jpegCompression = 90;
27
28 10
    public function getValue($name)
29
    {
30
        switch ($name) {
31 10
            case 'ThumbnailMIMEType':
32 3
                switch ($this->getValue('MIMEType')) {
33 3
                    case 'application/psd':
34
                        return 'image/png';
35 3
                    case 'image/tiff':
36
                        return 'image/jpeg';
37
                    default:
38 3
                        return $this->getValue('MIMEType');
39
                }
40
41
                // no break
42 10
            case 'Extension':
43
44 8
                switch ($this->getValue('MIMEType')) {
45 8
                    case 'application/psd':
46
                        return 'psd';
47
48 8
                    case 'image/tiff':
49
                        return 'tif';
50
51 8
                    case 'image/gif':
52
                        return 'gif';
53
54 8
                    case 'image/jpeg':
55
                        return 'jpg';
56
57 8
                    case 'image/png':
58 8
                        return 'png';
59
60
                    default:
61
                        throw new Exception('Unable to find photo extension for mime-type: '.$this->getValue('MIMEType'));
62
                }
63
64
                // no break
65
            default:
66 10
                return parent::getValue($name);
67
        }
68
    }
69
70
    /**
71
     * Runs getimagesize on the file and returns an array with the output
72
     *
73
     * @param string $filename
74
     * @param array $mediaInfo
75
     * @return array $mediaInfo
76
     */
77 2
    public static function analyzeFile($filename, $mediaInfo = [])
78
    {
79 2
        if (!$mediaInfo['imageInfo'] = getimagesize($filename)) {
80
            throw new Exception('Failed to read image file information');
81
        }
82
83
        // store image data
84 2
        $mediaInfo['width'] = $mediaInfo['imageInfo'][0];
85 2
        $mediaInfo['height'] = $mediaInfo['imageInfo'][1];
86 2
        $mediaInfo['duration'] = 0;
87
88 2
        return $mediaInfo;
89
    }
90
}
91