Documentation
¶
Index ¶
- func ConvertFileToPNG(ctx context.Context, inputPath string, outputPath string) (string, error)
- func ConvertToPNG(ctx context.Context, input any) ([]byte, error)
- func ConvertURLImageToPNG(ctx context.Context, url string) ([]byte, error)
- func DownloadFile(sourceURL string) (string, error)
- func DownloadImage(url string) ([]byte, error)
- func GetImageFormat(data []byte) (string, error)
- func IsPNG(data []byte) bool
- func SaveImageAsPNG(data []byte, outputPath string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertFileToPNG ¶
ConvertFileToPNG converts an image file to PNG format and saves it to the specified output path. If outputPath is empty, it will replace the original file extension with .png.
func ConvertToPNG ¶
ConvertToPNG converts an image from various formats (JPEG, GIF, etc.) to PNG. It accepts either a byte slice containing the image data or a file path. Returns the PNG image as a byte slice.
func ConvertURLImageToPNG ¶
ConvertURLImageToPNG downloads an image from a URL and converts it to PNG format. Returns the PNG image as a byte slice.
func DownloadFile ¶
DownloadFile downloads a file from a URL and saves it to a temporary directory with security validation. It follows redirects up to a maximum of 10 times. The filename is determined in the following order: 1. From Content-Disposition header if present and valid 2. From the final URL after redirects if valid 3. Falls back to a timestamp-based name if both sources are invalid
The function implements several security measures: - Validates filenames to prevent directory traversal - Restricts filenames to alphanumeric characters, dots, hyphens, underscores, and spaces - Ensures final path remains within temporary directory - Verifies path safety after normalization
Returns the path to the downloaded file and any error encountered.
func DownloadImage ¶
DownloadImage downloads an image from a given URL and returns it as a byte slice with retries
func GetImageFormat ¶
GetImageFormat detects the format of an image from its bytes. Returns the format as a string (e.g., "png", "jpeg", "gif").
func SaveImageAsPNG ¶
SaveImageAsPNG saves image data as a PNG file.
Types ¶
This section is empty.