From 1f5576e5d8cab67bf4c1112d8305417d1965bbc0 Mon Sep 17 00:00:00 2001 From: mathias234 Date: Tue, 2 Dec 2025 11:44:35 +0100 Subject: [PATCH] Add examples to readme --- README.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/README.md b/README.md index 8c877f2..f5be899 100644 --- a/README.md +++ b/README.md @@ -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