Add support for images #2

Merged
mathias234 merged 2 commits from feature/images into main 2025-12-02 10:45:52 +00:00
Showing only changes of commit 1f5576e5d8 - Show all commits

View File

@@ -112,6 +112,53 @@ Ezdoc::Document.create("output.docx") do |doc|
end
```
### Images
Images can be added to paragraphs, table cells, and list items. Supports PNG and JPEG formats.
```ruby
Ezdoc::Document.create("output.docx") do |doc|
# Simple image (uses native dimensions)
doc.p do
doc.image "photo.png"
end
# Image with explicit dimensions (inches, cm, or pixels)
doc.p do
doc.image "logo.png", width: "2in", height: "1in"
end
# Specify only width (height auto-calculated to maintain aspect ratio)
doc.p do
doc.image "banner.jpg", width: "5cm"
end
# Image with text in the same paragraph
doc.p do
doc.text "Company Logo: "
doc.image "logo.png", width: "0.5in", height: "0.5in"
end
# Image in a table cell
doc.table do
doc.tr do
doc.td "Product"
doc.td do
doc.image "product.jpg", width: "1in", height: "1in"
end
end
end
# Image in a list item
doc.ul do
doc.li do
doc.image "icon.png", width: "16px", height: "16px"
doc.text " List item with icon"
end
end
end
```
### Complete Example
```ruby
@@ -169,6 +216,7 @@ end
| `tr { }` | Table row |
| `td(text)` | Table cell with text |
| `td { }` | Table cell with block content |
| `image(path, width:, height:)` | Insert image (PNG/JPEG). Dimensions: `"2in"`, `"5cm"`, `"100px"`, or integer pixels |
## Development