Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion system/src/Grav/Common/Page/Medium/ImageMedium.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ public function derivatives($min_width, $max_width = 2500, $step = 200) {
$derivative->set('width', $width);
$derivative->set('height', $height);

$derivative->saveImage();
$derivative->resetImage();
$this->addAlternative($ratio, $derivative);
}
}
Expand Down Expand Up @@ -559,6 +561,14 @@ protected function image()
return $this;
}

/**
* Frees the cached image file.
*/
protected function resetImage()
{
$this->image = null;
}

/**
* Save the image with cache.
*
Expand Down Expand Up @@ -587,7 +597,9 @@ protected function saveImage()
$this->image->merge(ImageFile::open($overlay));
}

return $this->image->cacheFile($this->format, $this->quality);
$cachedPath = $this->image->cacheFile($this->format, $this->quality);
$this->set('filepath', $cachedPath);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line breaks image handling as the image quality gets worse and worse on every resize.

return $cachedPath;
}

/**
Expand Down