Documentation ¶
Overview ¶
Package imagecoding provides go bindings for en-/de-coding images using image processing c libraries found in common systems
Package imagecoding provides go bindings for en-/de-coding images using image processing c libraries found in common systems
Index ¶
- Constants
- Variables
- func ConfigHeif(data []byte) (image.Config, string, error)
- func ConfigJpeg(data []byte) (image.Config, string, error)
- func DecodeConfig(content []byte) (image.Config, string, error)
- func DefaultScale(pageWidth, pageHeight int) (imgWidth, imgHeight int, scaleFactor float64)
- func EncodeJpeg(buf *bytes.Buffer, img image.Image, quality int) ([]byte, error)
- func EncodePng(buf *bytes.Buffer, img image.Image) ([]byte, error)
- func EncodeWebP(buf *bytes.Buffer, img image.Image) ([]byte, error)
- func FixOrientation(img image.Image, orient Orientation) image.Image
- func ReOrientJpeg(file []byte, orient Orientation) ([]byte, error)
- func Transform(data []byte, grayscale bool, scale ScaleFunc) (out image.Image, width, height int, scaleFactor float64, err error)
- func TransformHeif(data []byte, grayscale bool, scale ScaleFunc) (out image.Image, width, height int, scaleFactor float64, err error)
- func TransformJpeg(data []byte, grayscale bool, scale ScaleFunc) (out image.Image, width, height int, scaleFactor float64, err error)
- type ImgFormat
- type Orientation
- type RGB
- type RGBImage
- type ScaleFunc
- type TurboJpegOperation
Constants ¶
const ( A4Short = 210 / 25.4 * 150 // 210 mm / 25.4 mm/inch * 150 ppi ≈ 1204 pixels A4Long = 297 / 25.4 * 150 // 297 mm / 25.4 mm/inch * 150 ppi ≈ 1754 pixels )
Variables ¶
var EmptyInputError = errors.New("empty input data")
var RGBModel = webp.RGBModel
Functions ¶
func DecodeConfig ¶
DecodeConfig is like image.DecodeConfig but supports additional formats For JPEGs it uses jpeg-turbos internal function for compatibility
func DefaultScale ¶
Calculcate at what scale to use for OCR optimized pages We prefer maximum what would be the equivalent for a A4 page at 150 ppi
func EncodePng ¶
EncodePng will encode an image.Gray to PNG bytes, using libpng's simplified API for performance
func FixOrientation ¶
func FixOrientation(img image.Image, orient Orientation) image.Image
FixOrientation uses the imaging library to correct for orientation
func ReOrientJpeg ¶
func ReOrientJpeg(file []byte, orient Orientation) ([]byte, error)
ReOrientJpeg will transform a JPEG into a top left (normal) orientation It returns a buffer with JPEG encoding
func Transform ¶
func Transform(data []byte, grayscale bool, scale ScaleFunc) (out image.Image, width, height int, scaleFactor float64, err error)
Transform scales, colormaps and orients an image according to input param
func TransformHeif ¶
func TransformJpeg ¶
func TransformJpeg(data []byte, grayscale bool, scale ScaleFunc) (out image.Image, width, height int, scaleFactor float64, err error)
TransformJpeg will scale and colormap an input JPEG file to an image.Gray or RGBImage This will use libjpeg-turbo to do it as efficiently as possible, utilizing DCT factors for fast scaling
Types ¶
type Orientation ¶
type Orientation uint8
Enum representation for Exif Orientation
const ( TopLeft Orientation = 1 TopRight Orientation = 2 BottomRight Orientation = 3 BottomLeft Orientation = 4 LeftTop Orientation = 5 RightTop Orientation = 6 RightBottom Orientation = 7 LeftBottom Orientation = 8 )
func GetOrientation ¶
func GetOrientation(reader io.Reader) Orientation
GetOrientation returns the image orientation from EXIF data https://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/
TopLeft 1: 0 degrees – the correct orientation, no adjustment is required. TopRight 2: 0 degrees, mirrored – image has been flipped back-to-front. BottomRight 3: 180 degrees – image is upside down. BottomLeft 4: 180 degrees, mirrored – image is upside down and flipped back-to-front. LeftTop 5: 90 degrees – image is on its side. RightTop 6: 90 degrees, mirrored – image is on its side and flipped back-to-front. RightBottom 7: 270 degrees – image is on its far side. LeftBottom 8: 270 degrees, mirrored – image is on its far side and flipped back-to-front.