Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kc0bfv/autophugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl <kc0bfv@gmail.com>2022-03-07 00:53:26 +0300
committerKarl <kc0bfv@gmail.com>2022-03-07 00:53:26 +0300
commit3d4a94519b5ef31c04dab4cc60277477b9fce0ee (patch)
tree56739b6ee6ac6747323fc2853b6f0d071b50f40d
parent0f3c2b64105b30e3905411a723056d06a6d9e92a (diff)
Add an advanced feature to change resize behavior
Added the "Fit" resize method as an option, to respond to issue #35
-rw-r--r--README.md7
-rw-r--r--layouts/_default/list.html12
2 files changed, 17 insertions, 2 deletions
diff --git a/README.md b/README.md
index d597c91..70dde87 100644
--- a/README.md
+++ b/README.md
@@ -157,7 +157,12 @@ Regardless of the number of resources you have, Hugo will only deploy the ones a
## Advanced Features
-Image resizing: normally you specify `thumb_width` and `full_width` in your configuration, and the qualities, to modify how Autophugo scales your images. Autophugo uses these values to build a string for Hugo's Resize function. You can specify that string directly though... Set `thumb_size` or `full_size` directly in your config to bypass the other ones. The format of the string is [documented here](https://gohugo.io/content-management/image-processing/).
+Image resizing: normally you specify `thumb_width` and `full_width` in your configuration, and the qualities, to modify how Autophugo scales your images. Autophugo uses these values to build a string for Hugo's Resize function. You can specify that string directly though... Set `thumb_size` or `full_size` directly in your config to bypass the other ones. The format of the string is [documented here](https://gohugo.io/content-management/image-processing/). You can specify `full_size` and `thumb_size` for the entire site, or in the `_index.md` for a specific subalbum.
+
+You can also change the method Hugo uses to resize your full-sized images (the option is not available for thumbnails). Hugo has both `Resize` and `Fit` methods that are appropriate for resizing the full-sized images. By default Autophugo uses `Resize`. By setting `full_resize_method` to `Fit` or `Resize` you can change that. You must also specify a `full_size` if you change to the `Fit` method. That's because both the height and width must be specified, and with `Resize` you only need one or the other. Again, the format of the `full_size` string is [documented here](https://gohugo.io/content-management/image-processing/). Here are some examples:
+
+* Scale an image down, keeping aspect ratio, to a max height of 960px and a max width of 960px, with a 90% quality: `full_resize_method = "fit"`, `full_size = "960x960 q90"`
+* Scale an image to a width of 960px, allowing whatever height is required for the original aspect ratio, with a 90% quality: `full_resize_method = "resize"`, `full_size = "960x q90"`
## Comparison to Phugo
diff --git a/layouts/_default/list.html b/layouts/_default/list.html
index caaefe6..1a9786a 100644
--- a/layouts/_default/list.html
+++ b/layouts/_default/list.html
@@ -9,6 +9,7 @@
{{- /* Calculate thumb_ and full_size from params, unless one is provided in the config. */}}
{{- $thumb_size := default (printf "%dx q%d" $thumb_width $thumb_quality) ($.Param "thumb_size") }}
+ {{- $full_resize_method := lower (default "resize" ($.Param "full_resize_method")) -}}
{{- $full_size := default (printf "%dx q%d" $full_width $full_quality) ($.Param "full_size") }}
{{- /* Build the list of sections and thumbnails */}}
@@ -130,7 +131,16 @@
{{- $weight := $img_dat.Get "weight" }}
{{- $taxonomies := $img_dat.Get "taxonomies" }}
{{- $thumb := $elem_val.Resize $thumb_resize_cmd }}
- {{- $full := $elem_val.Resize $full_resize_cmd }}
+
+ {{- $.Scratch.Set "full_resized" $thumb }}
+ {{- if (eq $full_resize_method "resize") }}
+ {{- $.Scratch.Set "full_resized" ($elem_val.Resize $full_resize_cmd) }}
+ {{- else if (eq $full_resize_method "fit") }}
+ {{- $.Scratch.Set "full_resized" ($elem_val.Fit $full_resize_cmd) }}
+ {{- else }}
+ {{- errorf "Invalid 'full_resize_method' specified! Must be resize or fit." }}
+ {{- end }}
+ {{- $full := $.Scratch.Get "full_resized" }}
{{- $new_img := dict "type" "image" "index" $elem_index "image" $elem_val "thumb" $thumb "full" $full "alt" $alt "phototitle" $phototitle "description" $description "weight" $weight "orig" $elem_val "taxonomies" $taxonomies }}