mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-30 23:01:04 +00:00
7732da9f93
Introduces the Crop method for image processing which implements gift.CropToSize. Also allows a smartCrop without resizing, and updates the documentation. Fixes #9499
27 lines
No EOL
968 B
HTML
27 lines
No EOL
968 B
HTML
{{ $original := .Page.Resources.GetMatch (printf "*%s*" (.Get 0)) }}
|
|
{{ $command := .Get 1 }}
|
|
{{ $options := .Get 2 }}
|
|
{{ if eq $command "Fit"}}
|
|
{{ .Scratch.Set "image" ($original.Fit $options) }}
|
|
{{ else if eq $command "Resize"}}
|
|
{{ .Scratch.Set "image" ($original.Resize $options) }}
|
|
{{ else if eq $command "Fill"}}
|
|
{{ .Scratch.Set "image" ($original.Fill $options) }}
|
|
{{ else if eq $command "Crop"}}
|
|
{{ .Scratch.Set "image" ($original.Crop $options) }}
|
|
{{ else }}
|
|
{{ errorf "Invalid image processing command: Must be one of Crop, Fit, Fill or Resize."}}
|
|
{{ end }}
|
|
{{ $image := .Scratch.Get "image" }}
|
|
<figure style="padding: 0.25rem; margin: 2rem 0; background-color: #cccc">
|
|
<img style="max-width: 100%; width: auto; height: auto;" src="{{ $image.RelPermalink }}" width="{{ $image.Width }}" height="{{ $image.Height }}">
|
|
<figcaption>
|
|
<small>
|
|
{{ with .Inner }}
|
|
{{ . }}
|
|
{{ else }}
|
|
.{{ $command }} "{{ $options }}"
|
|
{{ end }}
|
|
</small>
|
|
</figcaption>
|
|
</figure> |