{"record":{"id":"3855f3d1352b0fd4","repo":"gohugoio/hugo","slug":"final-image-height-will-be-less-than-1-pixel-chec","errorCode":null,"errorMessage":"final image height will be less than 1 pixel: check padding values","messagePattern":"final image height will be less than 1 pixel: check padding values","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/images/padding.go","lineNumber":39,"sourceCode":"\t\"github.com/gohugoio/gift\"\n)\n\nvar _ gift.Filter = (*paddingFilter)(nil)\n\ntype paddingFilter struct {\n\ttop, right, bottom, left int\n\tccolor                   color.Color // canvas color\n}\n\nfunc (f paddingFilter) Draw(dst draw.Image, src image.Image, options *gift.Options) {\n\tw := src.Bounds().Dx() + f.left + f.right\n\th := src.Bounds().Dy() + f.top + f.bottom\n\n\tif w < 1 {\n\t\tpanic(\"final image width will be less than 1 pixel: check padding values\")\n\t}\n\tif h < 1 {\n\t\tpanic(\"final image height will be less than 1 pixel: check padding values\")\n\t}\n\n\ti := image.NewRGBA(image.Rect(0, 0, w, h))\n\tdraw.Draw(i, i.Bounds(), image.NewUniform(f.ccolor), image.Point{}, draw.Src)\n\tgift.New().Draw(dst, i)\n\tgift.New().DrawAt(dst, src, image.Pt(f.left, f.top), gift.OverOperator)\n}\n\nfunc (f paddingFilter) Bounds(srcBounds image.Rectangle) image.Rectangle {\n\treturn image.Rect(0, 0, srcBounds.Dx()+f.left+f.right, srcBounds.Dy()+f.top+f.bottom)\n}\n","sourceCodeStart":21,"sourceCodeEnd":51,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/images/padding.go#L21-L51","documentation":"Thrown by the padding filter's Draw when the resulting canvas height is less than 1 pixel (padding.go:33-40). Height = source height + top + bottom; over-aggressive negative vertical padding drives the canvas non-positive.","triggerScenarios":"Passing top/bottom negative padding whose combined magnitude meets or exceeds the source height, e.g. a 30px-tall image with top=-50.","commonSituations":"Dynamic negative padding applied uniformly to images of differing heights; attempting to crop vertically via padding without bounds checking.","solutions":["Ensure |top + bottom| < source height with at least 1px remaining.","Prefer images.Crop for vertical cropping.","Clamp negative values to the image dimensions."],"exampleFix":"// before\n{{ $filters = $filters | append (images.Padding -200 0 -200 0) }}\n// after\n{{ $filters = $filters | append (images.Crop \"10x40 Center\") }}","handlingStrategy":"validation","validationCode":"{{ $h := $img.Height }}\n{{ if le (add $h (add $top $bottom)) 0 }}\n  {{ errorf \"negative padding exceeds image height %d\" $h }}\n{{ end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use images.Crop for vertical cropping.","Clamp top+bottom so the canvas stays >= 1px tall.","Check source height before applying negative vertical padding."],"tags":["image-filter","padding","crop","validation","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}