help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
go-cli-tool
/
internal
/
imgops
RSK World
go-cli-tool
Go CLI Tool v3.0 - Command-Line Interface with File Operations + Text Processing + System Monitoring + Cryptographic Tools + Network Utilities + HTTP Client + Image Processing + Cross-Platform Support + Modern Go Development
imgops
  • image.go2.1 KB
image.go
internal/imgops/image.go
Raw Download
Find: Go to:
/*
 * Project: Go CLI Tool
 * Category: Go Projects
 * Description: Command-line interface tool built with Go. Features file operations, text processing, command parsing, and system utilities.
 * Author: RSK World
 * Email: support@rskworld.in
 * Website: https://rskworld.in/contact.php
 * Year: 2026
 * Copyright (c) 2026 RSK World. All rights reserved.
 */

package imgops

import (
	"fmt"
	"image"
	_ "image/gif"
	_ "image/jpeg"
	"image/png"
	"os"
	"path/filepath"
	"strings"

	"go-cli-tool/internal/ui"
)

// GetImageInfo prints dimensions and format of an image file.
func GetImageInfo(filename string) {
	ui.Info(fmt.Sprintf("Analyzing image: %s", filename))

	file, err := os.Open(filename)
	if err != nil {
		ui.Error(fmt.Sprintf("Failed to open image file: %v", err))
		return
	}
	defer file.Close()

	img, format, err := image.DecodeConfig(file)
	if err != nil {
		ui.Error(fmt.Sprintf("Failed to decode image config: %v", err))
		return
	}

	ui.Success("Image analysis complete")
	ui.Header("IMAGE INFO")
	fmt.Printf("File: %s\n", filepath.Base(filename))
	fmt.Printf("Format: %s\n", strings.ToUpper(format))
	fmt.Printf("Width: %dpx\n", img.Width)
	fmt.Printf("Height: %dpx\n", img.Height)
	fmt.Printf("Resolution: %dx%d\n", img.Width, img.Height)
}

// ConvertToPNG converts an image to PNG format.
func ConvertToPNG(src, dst string) {
	ui.Info(fmt.Sprintf("Converting %s to PNG format", src))

	file, err := os.Open(src)
	if err != nil {
		ui.Error(fmt.Sprintf("Failed to open source image: %v", err))
		return
	}
	defer file.Close()

	img, format, err := image.Decode(file)
	if err != nil {
		ui.Error(fmt.Sprintf("Failed to decode image (%s): %v", format, err))
		return
	}

	outFile, err := os.Create(dst)
	if err != nil {
		ui.Error(fmt.Sprintf("Failed to create output file: %v", err))
		return
	}
	defer outFile.Close()

	err = png.Encode(outFile, img)
	if err != nil {
		ui.Error(fmt.Sprintf("Failed to encode PNG: %v", err))
		return
	}

	ui.Success(fmt.Sprintf("Successfully converted %s (%s) to PNG", src, strings.ToUpper(format)))
	fmt.Printf("Output saved to: %s\n", dst)
}
86 lines•2.1 KB
go

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer