resize

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BypolarInterpolate

func BypolarInterpolate(img image.Image, newWidth, newHeight int) image.Image

BypolarInterpolate resizes an image using Bypolar interpolation. This method calculates pixel values in the resized image by interpolating between the four nearest pixels in the original image. It provides smoother results compared to nearest neighbor interpolation, making it suitable for both enlarging and reducing images while maintaining better visual quality.

Parameters:

  • img: The input image to be resized
  • newWidth: The desired width of the resized image (in pixels)
  • newHeight: The desired height of the resized image (in pixels)

Returns:

  • image.Image

func NearestNeighbor

func NearestNeighbor(img image.Image, newWidth, newHeight int) image.Image

NearestNeighbor resizes an image using nearest neighbor interpolation. This is the simplest and fastest resizing algorithm that works by selecting the color of the nearest pixel in the original image for each pixel in the resized image. While efficient, it may produce pixelated results, especially when significantly enlarging images.

Parameters:

  • img: The input image to be resized
  • newWidth: The desired width of the resized image (in pixels)
  • newHeight: The desired height of the resized image (in pixels)

Returns:

  • image.Image

func NewAspectRatio

func NewAspectRatio(img image.Image, newWidth int) (int, int)

NewAspectRatio calculates the new dimensions for an image while preserving the aspect ratio. Given a new target width, this function computes the proportionally correct height to maintain the original image's proportions, preventing distortion.

Parameters:

  • img: The input image whose aspect ratio should be preserved
  • newWidth: The desired width of the resized image (in pixels)

Returns:

  • int: The requested new width (same as input newWidth)
  • int: The calculated new height that preserves aspect ratio

Types

This section is empty.

Jump to

Keyboard shortcuts

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