github.com/neohugo/neohugo@v0.123.8/resources/images/image_resource.go (about) 1 // Copyright 2024 The Hugo Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package images 15 16 import ( 17 "image" 18 19 "github.com/neohugo/neohugo/resources/images/exif" 20 "github.com/neohugo/neohugo/resources/resource" 21 ) 22 23 // ImageResource represents an image resource. 24 type ImageResource interface { 25 resource.Resource 26 ImageResourceOps 27 } 28 29 type ImageResourceOps interface { 30 // Height returns the height of the Image. 31 Height() int 32 33 // Width returns the width of the Image. 34 Width() int 35 36 // Process applies the given image processing options to the image. 37 Process(spec string) (ImageResource, error) 38 39 // Crop an image to match the given dimensions without resizing. 40 // You must provide both width and height. 41 // Use the anchor option to change the crop box anchor point. 42 // {{ $image := $image.Crop "600x400" }} 43 Crop(spec string) (ImageResource, error) 44 45 // Fill scales the image to the smallest possible size that will cover the specified dimensions in spec, 46 // crops the resized image to the specified dimensions using the given anchor point. 47 // The spec is space delimited, e.g. `200x300 TopLeft`. 48 Fill(spec string) (ImageResource, error) 49 50 // Fit scales down the image using the given spec. 51 Fit(spec string) (ImageResource, error) 52 53 // Resize resizes the image to the given spec. If one of width or height is 0, the image aspect 54 // ratio is preserved. 55 Resize(spec string) (ImageResource, error) 56 57 // Filter applies one or more filters to an Image. 58 // {{ $image := $image.Filter (images.GaussianBlur 6) (images.Pixelate 8) }} 59 Filter(filters ...any) (ImageResource, error) 60 61 // Exif returns an ExifInfo object containing Image metadata. 62 Exif() *exif.ExifInfo 63 64 // Colors returns a slice of the most dominant colors in an image 65 // using a simple histogram method. 66 Colors() ([]string, error) 67 68 // For internal use. 69 DecodeImage() (image.Image, error) 70 }