image_resource.go (1717B)
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 // Width returns the width of the Image. 33 Width() int 34 35 // Crop an image to match the given dimensions without resizing. 36 // You must provide both width and height. 37 // Use the anchor option to change the crop box anchor point. 38 // {{ $image := $image.Crop "600x400" }} 39 Crop(spec string) (ImageResource, error) 40 Fill(spec string) (ImageResource, error) 41 Fit(spec string) (ImageResource, error) 42 Resize(spec string) (ImageResource, error) 43 44 // Filter applies one or more filters to an Image. 45 // {{ $image := $image.Filter (images.GaussianBlur 6) (images.Pixelate 8) }} 46 Filter(filters ...any) (ImageResource, error) 47 48 // Exif returns an ExifInfo object containing Image metadata. 49 Exif() *exif.ExifInfo 50 51 // Internal 52 DecodeImage() (image.Image, error) 53 }