README
¶
Gopiq Examples
This directory contains comprehensive examples demonstrating the features and capabilities of the gopiq image processing library.
Files
Sample Image
sample_image.png- A colorful test image with geometric shapes (800x600 pixels)
Example Programs
-
basic_example.go- Demonstrates basic image operations- Loading images from bytes
- Grayscale conversion
- Resizing
- Cropping
- Chaining operations
-
watermark_example.go- Shows text watermarking capabilities- Different watermark positions (top-left, top-right, bottom-left, bottom-right, center)
- Custom styling (colors, sizes, offsets)
- Multiple watermark styles
-
grayscale_example.go- Performance comparison of grayscale methods- Regular grayscale conversion
- Fast parallel grayscale conversion
- Custom performance options
- Timing comparisons
-
resize_example.go- Comprehensive resize operations- Various size formats (thumbnail, medium, large, square, wide, tall)
- Aspect ratio preservation
- Chaining with other operations
-
crop_example.go- Image cropping demonstrations- Corner crops
- Center crops
- Grid-based cropping
- Error handling for invalid crops
-
comprehensive_example.go- Complete feature demonstration- All major features in one example
- Performance comparisons
- Error handling
- Memory efficiency
- Different output formats
Running the Examples
To run any example:
cd examples
go run <example_name>.go
For example:
go run basic_example.go
go run watermark_example.go
go run comprehensive_example.go
Generated Output Files
Each example generates various output images demonstrating different operations:
Basic Example Outputs
output_grayscale.png- Grayscale version of the sample imageoutput_resized.png- Resized to 400x300output_cropped.png- Cropped 200x150 portion
Watermark Example Outputs
watermark_top_left.png- Watermark in top-left positionwatermark_top_right.png- Watermark in top-right positionwatermark_bottom_left.png- Watermark in bottom-left positionwatermark_bottom_right.png- Watermark in bottom-right positionwatermark_center.png- Watermark in center positionwatermark_custom_style.png- Custom styled watermark
Grayscale Example Outputs
grayscale_regular.png- Standard grayscale conversiongrayscale_fast.png- Optimized parallel grayscale conversiongrayscale_custom_perf.png- Custom performance options
Resize Example Outputs
resize_thumbnail.png- 100x75 thumbnailresize_medium.png- 400x300 medium sizeresize_large.png- 1200x900 large sizeresize_square.png- 500x500 square formatresize_wide.png- 800x200 wide formatresize_tall.png- 200x800 tall formatresize_chain_grayscale.png- Resize + grayscale chainresize_aspect_ratio.png- Aspect ratio preserved resize
Crop Example Outputs
crop_top_left.png- Top-left corner cropcrop_top_right.png- Top-right corner cropcrop_bottom_left.png- Bottom-left corner cropcrop_bottom_right.png- Bottom-right corner cropcrop_center_square.png- Center square cropcrop_center_rect.png- Center rectangle cropcrop_small_detail.png- Small detail cropcrop_wide_strip.png- Wide strip cropcrop_tall_strip.png- Tall strip cropcrop_chain_resize.png- Crop + resize chaincrop_grid_*.png- 4x4 grid of crops
Comprehensive Example Outputs
comprehensive_basic.png- Basic operations resultcomprehensive_watermark_*.png- Various watermark stylescomprehensive_grayscale_*.png- Performance comparison resultscomprehensive_pipeline.png- Complex processing pipeline resultcomprehensive_format.png/.jpg- Different output formatscomprehensive_efficiency_*.png- Memory efficiency test results
Key Features Demonstrated
- Image Loading: Loading images from byte arrays
- Grayscale Conversion: Both regular and optimized parallel methods
- Resizing: High-quality Catmull-Rom interpolation
- Cropping: Precise rectangular cropping with bounds checking
- Watermarking: Text watermarks with customizable positioning and styling
- Chaining: Fluent API for combining multiple operations
- Performance: Parallel processing and performance optimization
- Error Handling: Comprehensive error checking and reporting
- Format Support: PNG and JPEG output formats
- Memory Efficiency: Object pooling and efficient memory usage
Performance Notes
The examples include performance comparisons showing:
- Fast grayscale conversion can be 1.4x to 5x faster than regular conversion
- Parallel processing is most beneficial for larger images
- Custom performance options allow fine-tuning for specific use cases
Error Handling
Examples demonstrate proper error handling for:
- Invalid crop coordinates
- Negative dimensions
- Empty watermark text
- Out-of-bounds operations
All examples include comprehensive error checking and informative error messages.
Documentation
¶
There is no documentation for this package.