Passed
Push — master ( fa28f5...070d6c )
by Jens
02:40
created

BoxCrop::Execute()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 2
eloc 12
nc 2
nop 1
dl 0
loc 25
rs 8.8571
c 2
b 0
f 1
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 library\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) $ratio = 1;
32
			
33
			// Define sizes
34
			$this->_destWidth = floor($originalWidth * $ratio);
35
			$this->_destHeight = floor($originalHeight * $ratio);
36
			
37
			// Define margins
38
			$this->_destX = floor(($this->_width  - $this->_destWidth) / 2);
39
			$this->_destY = floor(($this->_height - $this->_destHeight) / 2);
40
			
41
			// Execute the Crop method with the given parameters
42
			return parent::Execute($imageResource);
43
		}
44
	}
45
}