1
en Image Operations
zero edited this page 2025-06-05 09:38:49 +08:00

Image Operations

WordZero provides comprehensive image manipulation capabilities for inserting, positioning, and styling images in Word documents. This chapter covers image insertion, sizing, positioning, and advanced image features.

🖼️ Image Insertion

Basic Image Insertion

import "github.com/ZeroHawkeye/wordZero/pkg/document"

doc := document.New()

// Insert image from file
image, err := doc.AddImageFromFile("path/to/image.jpg")
if err != nil {
    log.Fatal(err)
}

// Insert image from byte data
imageData, _ := ioutil.ReadFile("image.png")
image2 := doc.AddImageFromBytes(imageData)

Image Formats

WordZero supports multiple image formats:

// Supported formats
// JPEG/JPG
doc.AddImageFromFile("photo.jpg")

// PNG (with transparency support)
doc.AddImageFromFile("logo.png")

// GIF
doc.AddImageFromFile("animation.gif")

// BMP
doc.AddImageFromFile("bitmap.bmp")

📐 Image Sizing

Automatic Sizing

// Insert image with original size
image := doc.AddImageFromFile("image.jpg")

// Auto-fit to page width
image.FitToPageWidth()

// Auto-fit to specific width (maintaining aspect ratio)
image.SetWidth(400) // pixels

// Auto-fit to specific height (maintaining aspect ratio)
image.SetHeight(300) // pixels

💡 Best Practices

1. Image Quality

  • Use appropriate resolution for your document
  • Optimize file sizes for better performance
  • Choose the right format for your content

2. Layout Considerations

  • Ensure images enhance the content
  • Use consistent sizing throughout the document
  • Consider text flow around images

3. Accessibility

  • Provide alternative text for images
  • Ensure sufficient contrast
  • Use images that support your message

Next Steps

Continue learning about document features:


Master image operations to create visually appealing documents!