github.com/linchen2chris/hugo@v0.0.0-20230307053224-cec209389705/resources/images/image_resource.go (about) 1 // Copyright 2022 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/gohugoio/hugo/resources/images/exif" 20 "github.com/gohugoio/hugo/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 // Crop an image to match the given dimensions without resizing. 37 // You must provide both width and height. 38 // Use the anchor option to change the crop box anchor point. 39 // {{ $image := $image.Crop "600x400" }} 40 Crop(spec string) (ImageResource, error) 41 42 // Fill scales the image to the smallest possible size that will cover the specified dimensions in spec, 43 // crops the resized image to the specified dimensions using the given anchor point. 44 // The spec is space delimited, e.g. `200x300 TopLeft`. 45 Fill(spec string) (ImageResource, error) 46 47 // Fit scales down the image using the given spec. 48 Fit(spec string) (ImageResource, error) 49 50 // Resize resizes the image to the given spec. If one of width or height is 0, the image aspect 51 // ratio is preserved. 52 Resize(spec string) (ImageResource, error) 53 54 // Filter applies one or more filters to an Image. 55 // {{ $image := $image.Filter (images.GaussianBlur 6) (images.Pixelate 8) }} 56 Filter(filters ...any) (ImageResource, error) 57 58 // Exif returns an ExifInfo object containing Image metadata. 59 Exif() *exif.ExifInfo 60 61 // Colors returns a slice of the most dominant colors in an image 62 // using a simple histogram method. 63 Colors() ([]string, error) 64 65 // Internal 66 DecodeImage() (image.Image, error) 67 }