This is not true. Tools such as ImageMagick will, by default, use the q value of the source file. Hugo does not do this. The default value is 75, regardless of the q value of the source file.
The anchor
option (Center
, TopLeft
, etc.) is irrelevant when resizing. This option is only applicable to the .Fill
method.
As @davidsneighbour explains, there is a significant reduction in processing time using a previous transformation as the source.
I created a minimal site with 25 JPEG photographs. Each image is approximately 6.0 MB, 4032x3024. Then I ranged through all of the images (sequential processing).
Before running each test, I cleared the cache with:
rm -rf resources/_gen/images
The time shown for each test is the average of 3 runs.
Test 1 - Original code
{{ range resources.Match "*.jpg" }}
{{ $image1600 := .Resize "1600x webp q85" }}
{{ $image1200 := .Resize "1200x webp q85" }}
{{ $image900 := .Resize "900x webp q85" }}
{{ $image600 := .Resize "600x webp q85" }}
{{ $image100 := .Resize "100x webp" }}
{{ end }}
68 seconds
Test 2 - Use result of initial transformation for subsequent transformations
{{ range resources.Match "*.jpg" }}
{{ $image1600 := .Resize "1600x webp q85" }}
{{ $image1200 := $image1600.Resize "1200x webp q85" }}
{{ $image900 := $image1600.Resize "900x webp q85" }}
{{ $image600 := $image1600.Resize "600x webp q85" }}
{{ $image100 := $image1600.Resize "100x webp" }}
{{ end }}
44 seconds (35% reduction compared to Test 1)
Test 3 - Same as Test 2 with cleaner code
In additional to cleaner code, this test proves that specifying the same format for subsequent transformations has no effect on performance.
{{ range resources.Match "*.jpg" }}
{{ $image1600 := .Resize "1600x webp q85" }}
{{ $image1200 := $image1600.Resize "1200x q85" }}
{{ $image900 := $image1600.Resize "900x q85" }}
{{ $image600 := $image1600.Resize "600x q85" }}
{{ $image100 := $image1600.Resize "100x" }}
{{ end }}
44 seconds (35% reduction compared to Test 1)
Test 4 - Use result of previous transformation for current transformation
{{ range resources.Match "*.jpg" }}
{{ $image1600 := .Resize "1600x webp q85" }}
{{ $image1200 := $image1600.Resize "1200x q85" }}
{{ $image900 := $image1200.Resize "900x q85" }}
{{ $image600 := $image900.Resize "600x q85" }}
{{ $image100 := $image600.Resize "100x" }}
{{ end }}
36 seconds (47% reduction compared to Test 1)
Test 5 - Same as Test 4 with q=75 (default) for all images
{{ range resources.Match "*.jpg" }}
{{ $image1600 := .Resize "1600x webp" }}
{{ $image1200 := $image1600.Resize "1200x" }}
{{ $image900 := $image1200.Resize "900x" }}
{{ $image600 := $image900.Resize "600x" }}
{{ $image100 := $image600.Resize "100x" }}
{{ end }}
34 seconds (50% reduction compared to Test 1)
Test 6 - Same as Test 4 with q=70 for all images
{{ range resources.Match "*.jpg" }}
{{ $image1600 := .Resize "1600x webp q70" }}
{{ $image1200 := $image1600.Resize "1200x q70" }}
{{ $image900 := $image1200.Resize "900x q70" }}
{{ $image600 := $image900.Resize "600x q70" I
{{ $image100 := $image600.Resize "100x q70" }}
{{ end }}
34 seconds (50% reduction compared to Test 1)
Test 7 - Same as Test 4 with q=50 for all images
I wouldn’t do this in most cases. I think the risk of poor image quality is too high.
{{ range resources.Match "*.jpg" }}
{{ $image1600 := .Resize "1600x webp q50" }}
{{ $image1200 := $image1600.Resize "1200x q50" }}
{{ $image900 := $image1200.Resize "900x q50" }}
{{ $image600 := $image900.Resize "600x q50" }}
{{ $image100 := $image600.Resize "100x q50" }}
{{ end }}
30 seconds (56% reduction compared to Test 1)