|
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; |
|
|
|
|
|
|
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) |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
$aSize = getimagesize($iImageUri); |
|
50
|
|
|
$rActualImage = imagecreatefromjpeg($iImageUri); |
|
51
|
|
|
|
|
52
|
|
|
$ImageChoisie = imagecreatefromjpeg($_FILES['ImageNews']['tmp_name']); |
|
|
|
|
|
|
53
|
|
|
$TailleImageChoisie = getimagesize($_FILES['ImageNews']['tmp_name']); |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
89
|
|
|
$NomImageExploitable = time(); |
|
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
header('Content-Type: image/jpeg'); |
|
92
|
|
|
imagejpeg($rNewImage , null, 100); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.