BoxCrop   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A Execute() 0 26 2
1
<?php
2
/**
3
 * BoxCrop
4
 *
5
 * @Author: Jens Kooij
6
 * @Version: 1.0
7
 * @package: JNS MVC
8
 * @Licence: http://creativecommons.org/licenses/by-nc-nd/3.0/ Attribution-NonCommercial-NoDerivs 3.0 Unported
9
 */
10
11
namespace CloudControl\Cms\images\methods {
12
13
    class BoxCrop extends Crop
14
    {
15
        /**
16
         * @param resource $imageResource
17
         * @return resource
18
         */
19
        public function Execute($imageResource)
20
        {
21
            // Define the origial width and height
22
            $originalWidth = imagesx($imageResource);
23
            $originalHeight = imagesy($imageResource);
24
25
            // Define the ratios
26
            $wRatio = $this->_width / $originalWidth;
27
            $hRatio = $this->_height / $originalHeight;
28
29
            // Define which ratio will be used, depending on which is the smallest side
30
            $ratio = min($hRatio, $wRatio);
31
            if ($ratio > 1) {
32
                $ratio = 1;
33
            }
34
35
            // Define sizes
36
            $this->_destWidth = floor($originalWidth * $ratio);
37
            $this->_destHeight = floor($originalHeight * $ratio);
38
39
            // Define margins
40
            $this->_destX = floor(($this->_width - $this->_destWidth) / 2);
41
            $this->_destY = floor(($this->_height - $this->_destHeight) / 2);
42
43
            // Execute the Crop method with the given parameters
44
            return parent::Execute($imageResource);
45
        }
46
    }
47
}