imageresizer

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package imageresizer provides functionality to resize images using ImageMagick.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IntPtr

func IntPtr(n int) *int

IntPtr takes an integer and returns a pointer to a newly allocated copy of it. This is useful when you need to pass an integer by reference, especially in scenarios where integer values are optional and a nil pointer is a valid state.

func Terminate added in v1.0.2

func Terminate()

Terminate releases resources used by imageResizer and ImageMagick. It is the responsibility of the caller to invoke this function after completing image resizing operations. Failing to call Terminate can lead to resource leaks as it cleans up the MagickWand instance and terminates the ImageMagick environment. This is crucial especially in long-running applications or those processing large numbers of images, to avoid excessive memory usage.

Types

type FilterType

type FilterType int
const (
	FILTER_UNDEFINED      FilterType = FilterType(imagick.FILTER_UNDEFINED)
	FILTER_POINT          FilterType = FilterType(imagick.FILTER_POINT)
	FILTER_BOX            FilterType = FilterType(imagick.FILTER_BOX)
	FILTER_TRIANGLE       FilterType = FilterType(imagick.FILTER_TRIANGLE)
	FILTER_HERMITE        FilterType = FilterType(imagick.FILTER_HERMITE)
	FILTER_HANNING        FilterType = FilterType(imagick.FILTER_HANNING)
	FILTER_HAMMING        FilterType = FilterType(imagick.FILTER_HAMMING)
	FILTER_BLACKMAN       FilterType = FilterType(imagick.FILTER_BLACKMAN)
	FILTER_GAUSSIAN       FilterType = FilterType(imagick.FILTER_GAUSSIAN)
	FILTER_QUADRATIC      FilterType = FilterType(imagick.FILTER_QUADRATIC)
	FILTER_CUBIC          FilterType = FilterType(imagick.FILTER_CUBIC)
	FILTER_CATROM         FilterType = FilterType(imagick.FILTER_CATROM)
	FILTER_MITCHELL       FilterType = FilterType(imagick.FILTER_MITCHELL)
	FILTER_JINC           FilterType = FilterType(imagick.FILTER_JINC)
	FILTER_SINC           FilterType = FilterType(imagick.FILTER_SINC)
	FILTER_SINC_FAST      FilterType = FilterType(imagick.FILTER_SINC_FAST)
	FILTER_KAISER         FilterType = FilterType(imagick.FILTER_KAISER)
	FILTER_WELSH          FilterType = FilterType(imagick.FILTER_WELSH)
	FILTER_PARZEN         FilterType = FilterType(imagick.FILTER_PARZEN)
	FILTER_BOHMAN         FilterType = FilterType(imagick.FILTER_BOHMAN)
	FILTER_BARTLETT       FilterType = FilterType(imagick.FILTER_BARTLETT)
	FILTER_LAGRANGE       FilterType = FilterType(imagick.FILTER_LAGRANGE)
	FILTER_LANCZOS        FilterType = FilterType(imagick.FILTER_LANCZOS)
	FILTER_LANCZOS_SHARP  FilterType = FilterType(imagick.FILTER_LANCZOS_SHARP)
	FILTER_LANCZOS2       FilterType = FilterType(imagick.FILTER_LANCZOS2)
	FILTER_LANCZOS2_SHARP FilterType = FilterType(imagick.FILTER_LANCZOS2_SHARP)
	FILTER_ROBIDOUX       FilterType = FilterType(imagick.FILTER_ROBIDOUX)
	FILTER_ROBIDOUX_SHARP FilterType = FilterType(imagick.FILTER_ROBIDOUX_SHARP)
	FILTER_COSINE         FilterType = FilterType(imagick.FILTER_COSINE)
	FILTER_SPLINE         FilterType = FilterType(imagick.FILTER_SPLINE)
	FILTER_SENTINEL       FilterType = FilterType(imagick.FILTER_SENTINEL)
	FILTER_LANCZOS_RADIUS FilterType = FilterType(imagick.FILTER_LANCZOS_RADIUS)
)

type ImageResizer added in v1.0.3

type ImageResizer interface {
	// Resize resizes the image located at imageFilePath according to the settings of the imageResizer.
	Resize(imageFilePath string) (string, error)
	// Destroy releases resources associated with the MagickWand.
	// It is the responsibility of the caller to invoke this function
	// on each ImageMagick object after the resize is complete to free up the memory.
	Destroy()
}

func New

func New(options ...Option) ImageResizer

New initializes a new imageResizer with provided options.

type Option

type Option func(*imageResizer)

Option is a function that configures an imageResizer. It is used in the functional options pattern for initializing imageResizer instances.

func WithCompressionQuality

func WithCompressionQuality(cq int) Option

WithCompressionQuality returns an Option that sets the compression quality for an imageResizer. The quality is an integer value typically ranging from 0 (low quality, high compression) to 100 (high quality, low compression).

func WithDimensions

func WithDimensions(width, height int) Option

WithDimensions returns an Option that sets the width and height for an imageResizer. If either width or height is not set (zero value), the original dimension of the image is retained.

func WithFilterType

func WithFilterType(ft FilterType) Option

WithFilterType returns an Option that sets the filter type for an imageResizer. FilterType determines the algorithm used for image resizing.

func WithOutputDir

func WithOutputDir(outputDir string) Option

WithOutputDir returns an Option that sets the output directory for an imageResizer. If an output directory is provided, resized images will be saved to this directory. If not set, images will be saved in the same directory as the original.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL