質問するログイン新規登録

質問編集履歴

1

メソッドの処理を変更

2017/07/12 08:49

投稿

HiroakiYamada
HiroakiYamada

スコア8

title CHANGED
File without changes
body CHANGED
@@ -58,18 +58,6 @@
58
58
  function transformImageSize($srcPath, $dstPath, $width, $height)
59
59
  {
60
60
  list($originalWidth, $originalHeight, $type) = getimagesize($srcPath);
61
- $diffW = '';
62
- $diffH = '';
63
- if($originalWidth > $originalHeight){
64
- $diffW = $originalHeight;
65
- $diffH = $originalHeight;
66
- }elseif($originalWidth < $originalHeight){
67
- $diffW = $originalWidth;
68
- $diffH = $originalWidth;
69
- }elseif($originalWidth === $originalHeight){
70
- $diffW = $originalWidth;
71
- $diffH = $originalHeight;
72
- }
73
61
  switch ($type) {
74
62
  case IMAGETYPE_JPEG:
75
63
  $source = imagecreatefromjpeg($srcPath);
@@ -86,13 +74,13 @@
86
74
 
87
75
  $canvas = imagecreatetruecolor($width, $height);
88
76
 
89
- //imagecopyresampled($canvas, $source, 0, 0, 0, 0, $width, $height, $originalWidth, $originalHeight);
77
+ imagecopyresampled($canvas, $source, 0, 0, 0, 0, $width, $height, $originalWidth, $originalHeight);
90
- imagecopyresampled($canvas, $source, 0, 0, 0, 0, $width, $height, $diffW, $diffH);
91
78
  imagejpeg($canvas, $dstPath, 100);
92
79
  imagedestroy($source);
93
80
  imagedestroy($canvas);
94
81
  }
95
82
 
83
+
96
84
  /* ----------------------------------------------------------
97
85
  * 内接サイズを計算する
98
86
  * ---------------------------------------------------------- */
@@ -119,17 +107,15 @@
119
107
  function makeThumbnail($srcPath, $dstPath, $maxWidth, $maxHeight)
120
108
  {
121
109
  list($originalWidth, $originalHeight) = getimagesize($srcPath);
110
+ if ($maxWidth > $originalWidth && $maxHeight > $originalHeight) {
111
+ copy($srcPath, $dstPath);
112
+ return;
113
+ }
114
+
122
115
  list($canvasWidth, $canvasHeight) = getContainSize($originalWidth, $originalHeight, $maxWidth, $maxHeight);
123
116
 
124
- // 元画像がリサイズするサイズより小さいときは元画像を使う
125
- if($canvasWidth >= $originalWidth){
126
- $canvasWidth = $originalWidth;
127
- }
128
- if($canvasHeight >= $originalWidth){
129
- $canvasHeight = $originalHeight;
130
- }
131
-
132
117
  transformImageSize($srcPath, $dstPath, $canvasWidth, $canvasHeight);
133
118
  }
134
119
 
120
+
135
121
  ```