Image::showImageInSize()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 47
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 47
rs 9.0303
c 0
b 0
f 0
cc 3
eloc 31
nc 3
nop 4
1
<?php
2
3
/**
4
 * Manage Image
5
 *
6
 * @category    lib
7
 * @author      Judicaël Paquet <[email protected]>
8
 * @copyright   Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93)
9
 * @license     https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël
10
 * @version     Release: 1.0.0
11
 * @filesource  https://github.com/las93/venus2
12
 * @link        https://github.com/las93
13
 * @since       1.0
14
 */
15
namespace Venus\lib;
16
17
/**
18
 * This class manage the Image
19
 *
20
 * @category    lib
21
 * @author      Judicaël Paquet <[email protected]>
22
 * @copyright   Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93)
23
 * @license     https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël
24
 * @version     Release: 1.0.0
25
 * @filesource  https://github.com/las93/venus2
26
 * @link        https://github.com/las93
27
 * @since       1.0
28
 */
29
class Image 
30
{
31
	/**
32
	 * the translation language
33
	 * @var string
34
	 */	
35
	private $_sLanguage = LANGUAGE;
0 ignored issues
show
Unused Code introduced by
The property $_sLanguage is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
36
37
    /**
38
     * set the language if you don't want take the default language of the configuration file
39
     *
40
     * @access public
41
     * @param int $iImageUri
42
     * @param  int $iWidth
43
     * @param  int $iHeight
44
     * @param bool $bKeepDimension
45
     * @return void
46
     */
47
	public static function showImageInSize(int $iImageUri, int $iWidth, int $iHeight, bool $bKeepDimension = false)
0 ignored issues
show
Coding Style introduced by
showImageInSize uses the super-global variable $_FILES which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
48
	{	
49
	    $aSize = getimagesize($iImageUri);
50
	    $rActualImage = imagecreatefromjpeg($iImageUri);
51
	    
52
	    $ImageChoisie = imagecreatefromjpeg($_FILES['ImageNews']['tmp_name']);
0 ignored issues
show
Unused Code introduced by
$ImageChoisie is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
53
        $TailleImageChoisie = getimagesize($_FILES['ImageNews']['tmp_name']);
0 ignored issues
show
Unused Code introduced by
$TailleImageChoisie is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
54
55
        $rNewImage = imagecreatetruecolor($iWidth , $iHeight);
56
57
        if ($bKeepDimension === false) {
58
        
59
            imagecopyresampled($rNewImage, $rActualImage, 0, 0, 0, 0, $iWidth, $iHeight, $aSize[0], $aSize[1]);
60
        }
61
        else {
62
        
63
            if ($aSize[0] > $aSize[1]) {
64
65
                $rWhite = imagecolorallocate($rNewImage, 255, 255, 255);
66
                imagefilledrectangle($rNewImage, 0, 0, $iWidth, $iHeight, $rWhite);
67
                $fCoef = $aSize[1] / $aSize[0];
68
                $iHeight = round($iWidth * $fCoef);
69
                $iDestY = round(($iWidth - $iHeight) / 2);
70
                $iDestX = 0;
71
            }
72
            else {
73
74
                $rWhite = imagecolorallocate($rNewImage, 255, 255, 255);
75
                imagefilledrectangle($rNewImage, 0, 0, $iWidth, $iHeight, $rWhite);
76
                $fCoef = $aSize[0] / $aSize[1];
77
                $iWidth = round($iHeight * $fCoef);
78
                $iDestX = round(($iHeight - $iWidth) / 2);
79
                $iDestY = 0;
80
            }
81
            
82
            $rWhite = imagecolorallocate($rNewImage, 255, 255, 255);
83
            imagefilledrectangle($rNewImage, 0, 0, $iWidth, $iHeight, $rWhite);
84
            imagecopyresampled($rNewImage, $rActualImage, $iDestX, $iDestY, 0, 0, $iWidth, $iHeight, $aSize[0], $aSize[1]);
85
        }
86
        
87
        imagedestroy($rActualImage);
88
        $NomImageChoisie = explode('.', $rNewImage);
0 ignored issues
show
Unused Code introduced by
$NomImageChoisie is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
89
        $NomImageExploitable = time();
0 ignored issues
show
Unused Code introduced by
$NomImageExploitable is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
90
      
91
        header('Content-Type: image/jpeg');
92
        imagejpeg($rNewImage , null, 100);
93
	}
94
}
95