|
19 | 19 | use function extension_loaded; |
20 | 20 | use function func_num_args; |
21 | 21 | use function function_exists; |
| 22 | +use function in_array; |
22 | 23 |
|
23 | 24 | /** |
24 | 25 | * Trait ImageMediaTrait |
@@ -53,6 +54,9 @@ trait ImageMediaTrait |
53 | 54 | /** @var bool */ |
54 | 55 | protected $watermark; |
55 | 56 |
|
| 57 | + /** @var bool */ |
| 58 | + protected $progressive; |
| 59 | + |
56 | 60 | /** @var array */ |
57 | 61 | public static $magic_actions = [ |
58 | 62 | 'resize', 'forceResize', 'cropResize', 'crop', 'zoomCrop', |
@@ -353,8 +357,12 @@ protected function image() |
353 | 357 | // Use existing cache folder or if it doesn't exist, create it. |
354 | 358 | $cacheDir = $locator->findResource('cache://images', true) ?: $locator->findResource('cache://images', true, true); |
355 | 359 |
|
356 | | - // Make sure we free previous image. |
357 | | - unset($this->image); |
| 360 | + // Make sure we free previous image. Assign null rather than unset(): unset() |
| 361 | + // removes the declared property, and every later write then falls through to |
| 362 | + // Data's __set() and lands in $items['image'], overwriting the media type's |
| 363 | + // own `image` settings with the ImageFile object. That is what silently |
| 364 | + // killed the default filters in 1.4.6. getgrav/grav#4284. |
| 365 | + $this->image = null; |
358 | 366 |
|
359 | 367 | /** @var MediaCollectionInterface $media */ |
360 | 368 | $media = $this->get('media'); |
@@ -382,6 +390,7 @@ protected function image() |
382 | 390 | $this->retina_scale = $config->get('system.images.cls.retina_scale', 1); |
383 | 391 |
|
384 | 392 | $this->watermark = $config->get('system.images.watermark.watermark_all', false); |
| 393 | + $this->progressive = $config->get('system.images.progressive_jpeg', true); |
385 | 394 |
|
386 | 395 | return $this; |
387 | 396 | } |
@@ -423,6 +432,14 @@ protected function saveImage() |
423 | 432 | $this->watermark(); |
424 | 433 | } |
425 | 434 |
|
| 435 | + // Queued last on purpose: GD keeps the interlace flag on the image resource, |
| 436 | + // and any operation that builds a new resource (a resize) drops it. Checked |
| 437 | + // against the resolved output format so a JPEG converted to PNG or WebP is |
| 438 | + // not interlaced along with it. getgrav/grav#4284. |
| 439 | + if ($this->progressive && in_array($this->format, ['jpg', 'jpeg'], true)) { |
| 440 | + $this->image->enableProgressive(); |
| 441 | + } |
| 442 | + |
426 | 443 | return $this->image->cacheFile($this->format, $this->quality, false, [$this->get('width'), $this->get('height'), $this->get('modified')]); |
427 | 444 | } |
428 | 445 | } |
0 commit comments