|
1 | 1 | /*
|
2 |
| - * JavaScript Load Image 1.7 |
| 2 | + * JavaScript Load Image 1.8.0 |
3 | 3 | * https://github.com/blueimp/JavaScript-Load-Image
|
4 | 4 | *
|
5 | 5 | * Copyright 2011, Sebastian Tschan
|
|
174 | 174 | minHeight,
|
175 | 175 | destWidth,
|
176 | 176 | destHeight,
|
177 |
| - scale; |
| 177 | + scaleUp = function () { |
| 178 | + var scale = Math.max( |
| 179 | + (minWidth || destWidth) / destWidth, |
| 180 | + (minHeight || destHeight) / destHeight |
| 181 | + ); |
| 182 | + if (scale > 1) { |
| 183 | + destWidth = Math.ceil(destWidth * scale); |
| 184 | + destHeight = Math.ceil(destHeight * scale); |
| 185 | + } |
| 186 | + }, |
| 187 | + scaleDown = function () { |
| 188 | + var scale = Math.min( |
| 189 | + (maxWidth || destWidth) / destWidth, |
| 190 | + (maxHeight || destHeight) / destHeight |
| 191 | + ); |
| 192 | + if (scale < 1) { |
| 193 | + destWidth = Math.ceil(destWidth * scale); |
| 194 | + destHeight = Math.ceil(destHeight * scale); |
| 195 | + } |
| 196 | + }; |
178 | 197 | if (useCanvas && options.orientation > 4) {
|
179 | 198 | maxWidth = options.maxHeight;
|
180 | 199 | maxHeight = options.maxWidth;
|
|
197 | 216 | sourceX = (width - sourceWidth) / 2;
|
198 | 217 | }
|
199 | 218 | } else {
|
| 219 | + if (options.contain || options.cover) { |
| 220 | + minWidth = maxWidth = maxWidth || minWidth; |
| 221 | + minHeight = maxHeight = maxHeight || minHeight; |
| 222 | + } |
200 | 223 | destWidth = width;
|
201 | 224 | destHeight = height;
|
202 |
| - scale = Math.max( |
203 |
| - (minWidth || destWidth) / destWidth, |
204 |
| - (minHeight || destHeight) / destHeight |
205 |
| - ); |
206 |
| - if (scale > 1) { |
207 |
| - destWidth = Math.ceil(destWidth * scale); |
208 |
| - destHeight = Math.ceil(destHeight * scale); |
209 |
| - } |
210 |
| - scale = Math.min( |
211 |
| - (maxWidth || destWidth) / destWidth, |
212 |
| - (maxHeight || destHeight) / destHeight |
213 |
| - ); |
214 |
| - if (scale < 1) { |
215 |
| - destWidth = Math.ceil(destWidth * scale); |
216 |
| - destHeight = Math.ceil(destHeight * scale); |
| 225 | + if (options.cover) { |
| 226 | + scaleDown(); |
| 227 | + scaleUp(); |
| 228 | + } else { |
| 229 | + scaleUp(); |
| 230 | + scaleDown(); |
217 | 231 | }
|
218 | 232 | }
|
219 | 233 | if (useCanvas) {
|
|
0 commit comments