Skip to content

Commit

Permalink
feat: allow specifying quality for resize method (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Jun 18, 2024
1 parent 3062ff4 commit c7524e3
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions layouts/partials/images/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
{{- $width := default (default "" .Width) ($params.Get "width" | strings.TrimSuffix "px") }}
{{- $originalWidth := 0 }}
{{- $naturalWidth := default $width ($params.Get "naturalWidth" | strings.TrimSuffix "px") }}
{{- $quality := $params.Get "quality" }}
{{- $wrapperClass := "" }}
{{- $sources := slice }}
{{/* Image alignment. */}}
Expand Down Expand Up @@ -72,12 +73,19 @@
{{- $originalWidth = $res.Width }}
{{- $originalHeight = $res.Height }}
{{/* Resize the image. */}}
{{- $resizeSpec := slice }}
{{- if and $width $height }}
{{- $res = .Resize (printf "%sx%s" (strings.TrimSuffix "px" $width) (strings.TrimSuffix "px" $height)) }}
{{- $resizeSpec = $resizeSpec | append (printf "%sx%s" (strings.TrimSuffix "px" $width) (strings.TrimSuffix "px" $height)) }}
{{- else if $width }}
{{- $res = .Resize (printf "%sx" (strings.TrimSuffix "px" $width)) }}
{{- $resizeSpec = $resizeSpec | append (printf "%sx" (strings.TrimSuffix "px" $width)) }}
{{- else if $height }}
{{- $res = .Resize (printf "x%s" (strings.TrimSuffix "px" $height)) }}
{{- $resizeSpec = $resizeSpec | append (printf "x%s" (strings.TrimSuffix "px" $height)) }}
{{- end }}
{{- with $quality }}
{{- $resizeSpec = $resizeSpec | append (printf "q%s" .) }}
{{- end }}
{{- with $resizeSpec }}
{{- $res = $res.Resize (delimit . " ") }}
{{- end }}
{{/* Cropping image. */}}
{{- with $params.Get "crop" }}
Expand Down

0 comments on commit c7524e3

Please sign in to comment.