mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-28 22:19:59 +02:00
Allow images to be cropped without being resized
Introduces the Crop method for image processing which implements gift.CropToSize. Also allows a smartCrop without resizing, and updates the documentation. Fixes #9499
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
aebde49b88
commit
7732da9f93
@@ -207,6 +207,21 @@ func (p *ImageProcessor) ApplyFiltersFromConfig(src image.Image, conf ImageConfi
|
||||
switch conf.Action {
|
||||
case "resize":
|
||||
filters = append(filters, gift.Resize(conf.Width, conf.Height, conf.Filter))
|
||||
case "crop":
|
||||
if conf.AnchorStr == smartCropIdentifier {
|
||||
bounds, err := p.smartCrop(src, conf.Width, conf.Height, conf.Filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// First crop using the bounds returned by smartCrop.
|
||||
filters = append(filters, gift.Crop(bounds))
|
||||
// Then center crop the image to get an image the desired size without resizing.
|
||||
filters = append(filters, gift.CropToSize(conf.Width, conf.Height, gift.CenterAnchor))
|
||||
|
||||
} else {
|
||||
filters = append(filters, gift.CropToSize(conf.Width, conf.Height, conf.Anchor))
|
||||
}
|
||||
case "fill":
|
||||
if conf.AnchorStr == smartCropIdentifier {
|
||||
bounds, err := p.smartCrop(src, conf.Width, conf.Height, conf.Filter)
|
||||
|
Reference in New Issue
Block a user