asciidoc-pubkit 1.4.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/README.md +11 -6
- data/docs/image-commands.md +171 -19
- data/docs/installation.md +1 -1
- data/lib/asciidoc_pubkit/cli.rb +3 -2
- data/lib/asciidoc_pubkit/image_commands.rb +178 -18
- data/lib/asciidoc_pubkit.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fcae540f3aa8af674b2ec7c408ed9aa7c67099a76592df85649cb92bdb67ffca
|
|
4
|
+
data.tar.gz: 77630797e44d089f14640c9e9390b0a6e55196456289cefe14257fa8eb98e5c6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0021abeb11fc9e444c4d0537121d1ee752e697095b9cb35f717401f43658bb4b3c7151da1e3ed1aa099d657ff318afb9ebc40918b2d9ceacbc2ee856bac8fb09
|
|
7
|
+
data.tar.gz: f7b2468001a818159744ab1a221c703d0264a66a27fb85b36a3a9e58230ab54d6a072f99c334a1332f98c5ad3d52937a7a999c0e3ae168b42a82a868b405c47a
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.4.1 - 2026-10-22
|
|
4
|
+
|
|
5
|
+
- Add read-only `image find` with inclusive file-size, total-pixel, pixel-dimension
|
|
6
|
+
and aspect-ratio bounds; portrait/landscape selection; stable metric sorting;
|
|
7
|
+
source locations and JSON reports. Reuse document image discovery and selection,
|
|
8
|
+
inspect all selected images before filtering, and preserve sources and pixels.
|
|
9
|
+
|
|
10
|
+
- Add opt-in `image scale --mode book`: scan selected unique document images,
|
|
11
|
+
calibrate median display height and area, and bound scaling with adjustable
|
|
12
|
+
overall, height and area factors. Report minimum-width conflicts and refuse
|
|
13
|
+
source application until resolved; never shrink existing widths cumulatively.
|
|
14
|
+
|
|
15
|
+
- Rename `image width` to `image scale`, without a compatibility alias.
|
|
16
|
+
- Add repeatable `--include` patterns to image list, stats and scale. Explicit
|
|
17
|
+
inclusion selects artwork; explicit exclusions still take precedence.
|
|
18
|
+
- Add `image scale --width PERCENT` for fixed source `scaledwidth` values.
|
|
19
|
+
Reject mixing fixed width with automatic coefficient or bound options.
|
|
20
|
+
- Preserve preview, diff, explicit application and safe source editing behavior.
|
|
21
|
+
|
|
3
22
|
## 1.4.0 - 2026-10-22
|
|
4
23
|
|
|
5
24
|
- Add document-based `image list`, `image stats` and `image width`. Resolve active
|
data/README.md
CHANGED
|
@@ -16,7 +16,7 @@ and books on health, exercise, and sports science published under
|
|
|
16
16
|
The experience informs the toolkit's writing criteria, contextual review prompts,
|
|
17
17
|
and checks for preserving manuscript content during revision.
|
|
18
18
|
|
|
19
|
-
Version 1.4.
|
|
19
|
+
Version 1.4.1 provides document-based image inspection and display sizing,
|
|
20
20
|
document inspection, explicit prose-only mechanical replacements, and Japanese
|
|
21
21
|
and English manuscript review. Inspect a book's outline,
|
|
22
22
|
metadata, and local cross-references; preview and apply your replacement rules;
|
|
@@ -35,10 +35,15 @@ Version 1.4.0 also compares explicit but vague actor names by their actual
|
|
|
35
35
|
responsibility; see [actor wording](docs/writing.md). This guidance adds no
|
|
36
36
|
detector or automatic replacement rules.
|
|
37
37
|
|
|
38
|
-
Version 1.4.
|
|
39
|
-
and `image width
|
|
38
|
+
Version 1.4.1 provides document-based `image list`, `image stats`,
|
|
39
|
+
`image find` and `image scale` (renamed from `image width`, without a compatibility alias). Use
|
|
40
|
+
`--include` to select images and `--width` for a fixed percentage; omit `--width`
|
|
41
|
+
for automatic aspect-ratio sizing. `--mode book` uses document-wide median
|
|
42
|
+
height/area budgets, with review reports for conflicting minimum widths. Collect images referenced by `book.adoc`, summarize their
|
|
40
43
|
pixel dimensions and file sizes, or explicitly update source `scaledwidth`
|
|
41
|
-
attributes from aspect ratios.
|
|
44
|
+
attributes from aspect ratios. Use `image find` to filter by byte size, total pixels,
|
|
45
|
+
pixel dimensions, portrait/landscape orientation or aspect-ratio bounds, with
|
|
46
|
+
optional sorting and JSON output. Image pixels are unchanged. See
|
|
42
47
|
[image commands](docs/image-commands.md) for selection, tuning, ImageMagick
|
|
43
48
|
requirements, preservation rules and Make integration.
|
|
44
49
|
|
|
@@ -74,11 +79,11 @@ see [JSON identifiers and explanatory strings](docs/writing.md#json-identifiers-
|
|
|
74
79
|
|
|
75
80
|
## Available features
|
|
76
81
|
|
|
77
|
-
The following commands are available in version 1.4.
|
|
82
|
+
The following commands are available in version 1.4.1.
|
|
78
83
|
|
|
79
84
|
| Feature | Commands | Behavior |
|
|
80
85
|
| --- | --- | --- |
|
|
81
|
-
| [Document images](docs/image-commands.md) | `image list`, `image stats`, `image
|
|
86
|
+
| [Document images](docs/image-commands.md) | `image list`, `image stats`, `image find`, `image scale` | Inspect and filter referenced block images; preview or explicitly apply source display widths |
|
|
82
87
|
| [Document outline](docs/document-commands.md#document-commands) | `document toc` | Print parsed section titles as text or JSON, including source locations, with optional depth and outline numbering |
|
|
83
88
|
| [Book metadata](docs/document-commands.md#document-commands) | `document info` | Extract book attributes as text or JSON |
|
|
84
89
|
| [Cross-reference checks](docs/document-commands.md#document-commands) | `document check-xrefs` | Report unresolved local cross-references with source locations |
|
data/docs/image-commands.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Document-based image commands (v1.4.
|
|
1
|
+
# Document-based image commands (v1.4.1)
|
|
2
2
|
|
|
3
3
|
All commands take an AsciiDoc entry document, such as `book.adoc`. They do not
|
|
4
4
|
accept a standalone image file or scan an arbitrary directory. They require Ruby
|
|
@@ -9,11 +9,15 @@ No Python, MeCab, AI, network fetch, or pixel modification is involved.
|
|
|
9
9
|
asciidoc-pubkit image list book.adoc
|
|
10
10
|
asciidoc-pubkit image list book.adoc --json
|
|
11
11
|
asciidoc-pubkit image stats book.adoc --json
|
|
12
|
-
asciidoc-pubkit image
|
|
13
|
-
asciidoc-pubkit image
|
|
14
|
-
asciidoc-pubkit image
|
|
12
|
+
asciidoc-pubkit image find book.adoc --portrait
|
|
13
|
+
asciidoc-pubkit image scale book.adoc
|
|
14
|
+
asciidoc-pubkit image scale book.adoc --diff
|
|
15
|
+
asciidoc-pubkit image scale book.adoc --in-place
|
|
15
16
|
```
|
|
16
17
|
|
|
18
|
+
`image scale` replaces the v1.4.0 `image width` command. The old name is no
|
|
19
|
+
longer accepted.
|
|
20
|
+
|
|
17
21
|
## Discovery and selection
|
|
18
22
|
|
|
19
23
|
Asciidoctor resolves active includes, attributes, conditional directives, and the
|
|
@@ -21,7 +25,7 @@ Asciidoctor resolves active includes, attributes, conditional directives, and th
|
|
|
21
25
|
directory, as in Asciidoctor, rather than each included file. Only parsed block
|
|
22
26
|
`image::` macros are collected. Inline `image:` macros, image text inside code or
|
|
23
27
|
comments, cover attributes without a block reference, and unreferenced files are
|
|
24
|
-
outside the
|
|
28
|
+
outside the collection scope. An AsciiDoc table's separate inner documents
|
|
25
29
|
are not traversed in this version.
|
|
26
30
|
|
|
27
31
|
The default boundary is the entry document's directory. `--base-dir DIR` changes
|
|
@@ -38,12 +42,18 @@ or `title-logo-image` assets, are excluded. `--include-artwork` disables these
|
|
|
38
42
|
built-in artwork exclusions; it does not collect assets that only appear in
|
|
39
43
|
attributes. Use `--exclude` for artwork with other names. Patterns match an image
|
|
40
44
|
basename or its path relative to the base directory. Repeat the flag for multiple
|
|
41
|
-
patterns. `--
|
|
45
|
+
patterns. Repeat `--include GLOB` to select only images matching any supplied
|
|
46
|
+
pattern (OR). Explicit inclusion overrides built-in artwork exclusions, including
|
|
47
|
+
cover asset references; explicit `--exclude` patterns still win. Matching uses the
|
|
48
|
+
same basename or base-relative path rules as exclusion. Without `--include`, the
|
|
49
|
+
existing default selection remains in effect. The filter applies to list, stats, find
|
|
50
|
+
and scale; an unmatched include selects zero images without modifying sources.
|
|
51
|
+
`--only FILE` selects references from one included source; it does not
|
|
42
52
|
mean one image, and the file must be part of the parsed document.
|
|
43
53
|
|
|
44
54
|
```sh
|
|
45
55
|
asciidoc-pubkit image list book.adoc --exclude 'special-*.png' --json
|
|
46
|
-
asciidoc-pubkit image
|
|
56
|
+
asciidoc-pubkit image scale book.adoc --only chapters/intro.adoc --diff
|
|
47
57
|
asciidoc-pubkit image list book.adoc -a edition-en -a diagrams=1
|
|
48
58
|
```
|
|
49
59
|
|
|
@@ -61,7 +71,86 @@ height, aspect ratio and bytes. Repeated references are not counted twice in
|
|
|
61
71
|
image statistics. With no selected images, totals are zero and min/max/mean are
|
|
62
72
|
null. Both commands are read-only; redirect stdout to save their reports.
|
|
63
73
|
|
|
64
|
-
##
|
|
74
|
+
## Find images (v1.4.1)
|
|
75
|
+
|
|
76
|
+
`image find` is read-only. It applies the shared document selection above first,
|
|
77
|
+
then filters the selected physical images by file size, pixel dimensions, total
|
|
78
|
+
pixels and aspect ratio. It does not measure rendered page size or interpret
|
|
79
|
+
image contents. No condition means all selected images.
|
|
80
|
+
|
|
81
|
+
```sh
|
|
82
|
+
asciidoc-pubkit image find book.adoc --min-bytes 1MiB
|
|
83
|
+
asciidoc-pubkit image find book.adoc --min-pixels 4000000
|
|
84
|
+
asciidoc-pubkit image find book.adoc --min-pixel-height 2000
|
|
85
|
+
asciidoc-pubkit image find book.adoc --portrait
|
|
86
|
+
asciidoc-pubkit image find book.adoc --landscape
|
|
87
|
+
asciidoc-pubkit image find book.adoc --max-aspect-ratio 0.5
|
|
88
|
+
asciidoc-pubkit image find book.adoc --min-aspect-ratio 2
|
|
89
|
+
asciidoc-pubkit image find book.adoc --min-aspect-ratio 0.5 --max-aspect-ratio 0.8
|
|
90
|
+
asciidoc-pubkit image find book.adoc --min-bytes 1MiB --portrait --sort bytes --order desc --json
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
| Options | Measurement |
|
|
94
|
+
| --- | --- |
|
|
95
|
+
| `--min-bytes SIZE`, `--max-bytes SIZE` | File size in bytes |
|
|
96
|
+
| `--min-pixels N`, `--max-pixels N` | Pixel width multiplied by pixel height |
|
|
97
|
+
| `--min-pixel-width N`, `--max-pixel-width N` | Pixel width, distinct from scale's display-width percentage |
|
|
98
|
+
| `--min-pixel-height N`, `--max-pixel-height N` | Pixel height |
|
|
99
|
+
| `--min-aspect-ratio R`, `--max-aspect-ratio R` | Pixel width divided by pixel height |
|
|
100
|
+
| `--portrait` | Height strictly greater than width |
|
|
101
|
+
| `--landscape` | Width strictly greater than height |
|
|
102
|
+
|
|
103
|
+
All numeric bounds are inclusive and all conditions combine with AND. A smaller
|
|
104
|
+
aspect ratio means a taller image: `--max-aspect-ratio 0.5` selects images at least
|
|
105
|
+
twice as tall as they are wide. Ratios use unrounded values for filtering.
|
|
106
|
+
Portrait and landscape exclude squares and cannot be supplied together.
|
|
107
|
+
Combining orientation with incompatible numeric bounds simply matches no images.
|
|
108
|
+
|
|
109
|
+
Byte sizes accept nonnegative integers, optionally followed immediately by
|
|
110
|
+
case-sensitive `B`, `KB`, `MB`, `KiB` or `MiB`. KB/MB use powers of 1000;
|
|
111
|
+
KiB/MiB use powers of 1024. Bare integers are bytes. Fractional byte sizes are
|
|
112
|
+
not accepted. Pixel counts and dimensions must be positive integers; aspect
|
|
113
|
+
ratios must be finite positive numbers. A minimum greater than its maximum is
|
|
114
|
+
an argument error.
|
|
115
|
+
|
|
116
|
+
Default output follows first-reference order. `--sort` accepts `bytes`, `pixels`,
|
|
117
|
+
`pixel-width`, `pixel-height` or `aspect-ratio`. With a sort metric, the default
|
|
118
|
+
order is `desc`; `--order asc` selects ascending order. Equal values retain
|
|
119
|
+
first-reference order in either direction. `--order` requires `--sort`.
|
|
120
|
+
|
|
121
|
+
Text output reports each matching physical image once, with dimensions, aspect
|
|
122
|
+
ratio, total pixels, bytes, reference count, and each selected reference's source
|
|
123
|
+
file and line. Unmapped locations are marked as unknown. The summary distinguishes
|
|
124
|
+
matching images from the selected population before numeric/orientation filtering.
|
|
125
|
+
|
|
126
|
+
JSON retains the inventory's `images`, `image_count`, `reference_count`, `excluded`,
|
|
127
|
+
document, boundary and scope fields. Image/reference counts describe matches;
|
|
128
|
+
`selected_image_count` and `selected_reference_count` describe the population
|
|
129
|
+
before numeric/orientation filtering. Each matching image adds `pixels` to the
|
|
130
|
+
normal inventory fields and retains its selected references. `filters` records
|
|
131
|
+
normalized numeric bounds in bytes/pixels/ratios and explicit orientation
|
|
132
|
+
booleans. `sort` and `order` are null in document order, otherwise they record the
|
|
133
|
+
metric and effective direction. Numeric nonmatches are not added to `excluded`,
|
|
134
|
+
which continues to describe shared discovery/selection exclusions.
|
|
135
|
+
|
|
136
|
+
All selected images are inspected before numeric/orientation filtering. Missing
|
|
137
|
+
or unsupported selected images fail with exit 2 even if they might not match;
|
|
138
|
+
inspection failures are never hidden as nonmatches. Successful empty searches
|
|
139
|
+
return 0. No source or pixel writes, AI calls, or network fetches occur.
|
|
140
|
+
|
|
141
|
+
## Display scaling and source edits
|
|
142
|
+
|
|
143
|
+
Use `--width PERCENT` for a fixed `scaledwidth` (finite, greater than 0 and at most
|
|
144
|
+
100). Preserve fractional values. It cannot be combined with explicitly supplied
|
|
145
|
+
`--height-width-ratio`, `--min-width`, or `--max-width`. Default automatic bounds
|
|
146
|
+
do not restrict fixed widths. Omit `--width` for automatic aspect-ratio sizing.
|
|
147
|
+
|
|
148
|
+
```sh
|
|
149
|
+
asciidoc-pubkit image scale book.adoc --include 'part-*' --include 'chapter-*' \
|
|
150
|
+
--width 100 --diff
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Automatic calculation
|
|
65
154
|
|
|
66
155
|
```text
|
|
67
156
|
raw width (%) = 100 × height-width-ratio × pixel width / pixel height
|
|
@@ -76,6 +165,7 @@ minimum 40%, maximum 100%. A square uses 80%, a 3:4 image 60%, and width/height
|
|
|
76
165
|
|
|
77
166
|
| Option | Default | Behavior |
|
|
78
167
|
| --- | --- | --- |
|
|
168
|
+
| `--width PERCENT` | unset | Fixed width; disables automatic sizing |
|
|
79
169
|
| `--height-width-ratio NUMBER` | `0.8` | Display height / text-area width coefficient |
|
|
80
170
|
| `--min-width PERCENT` | `40` | Smallest permitted display width |
|
|
81
171
|
| `--max-width PERCENT` | `100` | Largest permitted display width |
|
|
@@ -89,7 +179,7 @@ Coefficients must be finite and positive, and widths must satisfy
|
|
|
89
179
|
`--dry-run` or `--diff`; `--diff` cannot be combined with `--json`.
|
|
90
180
|
|
|
91
181
|
```sh
|
|
92
|
-
asciidoc-pubkit image
|
|
182
|
+
asciidoc-pubkit image scale book.adoc --height-width-ratio 0.7 \
|
|
93
183
|
--min-width 50 --max-width 100 --exclude 'manual.png' --diff
|
|
94
184
|
```
|
|
95
185
|
|
|
@@ -108,7 +198,7 @@ conversion; this does not impose a universal CSS width on every backend.
|
|
|
108
198
|
Source provenance is attached only in the parser's memory before include
|
|
109
199
|
lookahead can lose its location. No internal metadata is written to source.
|
|
110
200
|
Unsupported or unmapped source forms are not guessed: list/stats can report them,
|
|
111
|
-
but
|
|
201
|
+
but scale refuses an unsafe edit. Duplicate `scaledwidth` declarations are rejected.
|
|
112
202
|
A reused source macro can be edited once when all references request the same
|
|
113
203
|
result; conflicting expansions or an excluded reuse block the edit. Separate
|
|
114
204
|
attributes or macros across multiple lines are not reconstructed.
|
|
@@ -118,10 +208,15 @@ staged in their own directories with their modes preserved. Source snapshots
|
|
|
118
208
|
are checked for concurrent changes. A failed multi-file replacement rolls back
|
|
119
209
|
already installed changes, without overwriting a later concurrent writer's edits.
|
|
120
210
|
Repeated execution with the same inputs is idempotent. There is no `--output`
|
|
121
|
-
or `--output-dir` mode
|
|
211
|
+
or `--output-dir` mode; a single output file cannot represent updates
|
|
122
212
|
across several included files. Use preview/diff to review changes first.
|
|
123
213
|
|
|
124
|
-
|
|
214
|
+
JSON settings report `mode: fixed` with `width`, or `mode: automatic` with the
|
|
215
|
+
coefficient and bounds. A `minimum_limited` image also gets a notice in text
|
|
216
|
+
previews: its minimum display width can make its height exceed the target.
|
|
217
|
+
|
|
218
|
+
Image whitespace is included in the pixel dimensions. The algorithm does not
|
|
219
|
+
infer flow direction, text density or legibility from the pixels. At the minimum width a
|
|
125
220
|
very tall figure can still exceed a page, and text may require a larger width.
|
|
126
221
|
The coefficient and bounds are tuning values, not KDP requirements. Run the
|
|
127
222
|
book build, EPUBCheck and Kindle Previewer after applying source changes.
|
|
@@ -130,6 +225,62 @@ Successful commands, previews and empty collections return 0. Invalid arguments,
|
|
|
130
225
|
parse errors, missing images and unsafe/unwritable source edits return 2. This
|
|
131
226
|
does not replace manuscript review verification or establish publication readiness.
|
|
132
227
|
|
|
228
|
+
## Book-wide sizing
|
|
229
|
+
|
|
230
|
+
Opt in with `--mode book`; the default remains `--mode automatic`. Fixed
|
|
231
|
+
`--width` cannot be combined with a mode or automatic-sizing options.
|
|
232
|
+
|
|
233
|
+
```sh
|
|
234
|
+
asciidoc-pubkit image scale book.adoc --mode book --json
|
|
235
|
+
asciidoc-pubkit image scale book.adoc --mode book --min-width 30 --diff
|
|
236
|
+
asciidoc-pubkit image scale book.adoc --mode book --min-width 30 --in-place
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
First compute baseline fractions `s` from the automatic formula above for every
|
|
240
|
+
selected unique physical image. For aspect ratio `r = pixel width / pixel height`,
|
|
241
|
+
compute baseline height `s/r` and area `s*s/r`. Use their medians (the arithmetic
|
|
242
|
+
mean of the two middle values for an even count), without weighting repeated
|
|
243
|
+
references. Artwork remains excluded by default, so run fixed artwork scaling
|
|
244
|
+
separately. Explicit selection changes the calibration population. This mode
|
|
245
|
+
rejects `--only` to avoid accidentally calibrating a single included source.
|
|
246
|
+
It measures all selected images from the document, not the filesystem directory.
|
|
247
|
+
|
|
248
|
+
| Option | Default | Meaning |
|
|
249
|
+
| --- | --- | --- |
|
|
250
|
+
| `--scale-factor NUMBER` | 0.9 | Multiply each baseline width |
|
|
251
|
+
| `--height-factor NUMBER` | 1 | Multiply median baseline height for the height cap |
|
|
252
|
+
| `--area-factor NUMBER` | 0.8 | Multiply median baseline area for the area cap |
|
|
253
|
+
|
|
254
|
+
These factors require `--mode book` and must be finite, positive and at most 1.
|
|
255
|
+
The automatic coefficient and bounds still determine the baseline. Each new
|
|
256
|
+
fractional width is:
|
|
257
|
+
|
|
258
|
+
```text
|
|
259
|
+
height_cap = median(s/r) * height_factor
|
|
260
|
+
area_cap = median(s*s/r) * area_factor
|
|
261
|
+
new_s = min(s * scale_factor, height_cap * r, sqrt(area_cap * r))
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Convert to percent and round down to one decimal so rounding never exceeds a
|
|
265
|
+
budget. Recalculate baselines from image dimensions on each run; never shrink
|
|
266
|
+
existing `scaledwidth` values cumulatively. Changing the image population or
|
|
267
|
+
options intentionally changes the result. An empty population has null medians
|
|
268
|
+
and caps and does not edit any source.
|
|
269
|
+
|
|
270
|
+
A candidate below `--min-width` (or zero after rounding) is a conflict. Previews
|
|
271
|
+
return success, print a notice on stderr, and report every conflict in JSON
|
|
272
|
+
(`conflicts`, `requires_review`, `proposed_width_percent`). Conflicted references
|
|
273
|
+
are not included in the proposed source diff; their sources stay unchanged.
|
|
274
|
+
`--in-place` fails with exit 2 before any source write if any conflict exists.
|
|
275
|
+
Lower the minimum width or revise the selection/factors and preview again; no
|
|
276
|
+
minimum is silently forced above the height/area caps. Normal reports show
|
|
277
|
+
candidate widths and review notices; JSON additionally includes calibration
|
|
278
|
+
medians, caps, baseline widths, and predicted display heights/areas.
|
|
279
|
+
|
|
280
|
+
All heights use text-area width as the unit; areas use text-area width squared.
|
|
281
|
+
These are not percentages of viewport height or guarantees of Kindle pagination.
|
|
282
|
+
Image pixels, whitespace, flow direction and text legibility are not interpreted.
|
|
283
|
+
|
|
133
284
|
## Make integration
|
|
134
285
|
|
|
135
286
|
Call width adjustment before the converter reads the source document:
|
|
@@ -140,18 +291,19 @@ IMAGE_HEIGHT_WIDTH_RATIO ?= 0.8
|
|
|
140
291
|
IMAGE_MIN_WIDTH ?= 40
|
|
141
292
|
IMAGE_MAX_WIDTH ?= 100
|
|
142
293
|
IMAGE_SELECTION_OPTS ?=
|
|
143
|
-
|
|
294
|
+
IMAGE_SCALE_OPTS = --height-width-ratio $(IMAGE_HEIGHT_WIDTH_RATIO) --min-width $(IMAGE_MIN_WIDTH) --max-width $(IMAGE_MAX_WIDTH) $(IMAGE_SELECTION_OPTS)
|
|
144
295
|
|
|
145
|
-
.PHONY: image-list image-stats image-
|
|
296
|
+
.PHONY: image-list image-stats image-scale
|
|
146
297
|
image-list:
|
|
147
298
|
$(ASCIIDOC_PUBKIT) image list book.adoc $(IMAGE_SELECTION_OPTS)
|
|
148
299
|
image-stats:
|
|
149
300
|
$(ASCIIDOC_PUBKIT) image stats book.adoc $(IMAGE_SELECTION_OPTS)
|
|
150
|
-
image-
|
|
151
|
-
$(ASCIIDOC_PUBKIT) image
|
|
301
|
+
image-scale:
|
|
302
|
+
$(ASCIIDOC_PUBKIT) image scale book.adoc --include 'part-*' --include 'chapter-*' --width 100 --in-place
|
|
303
|
+
$(ASCIIDOC_PUBKIT) image scale book.adoc $(IMAGE_SCALE_OPTS) --in-place
|
|
152
304
|
```
|
|
153
305
|
|
|
154
|
-
Use your build's pre-generation prerequisite hook to run `image-
|
|
306
|
+
Use your build's pre-generation prerequisite hook to run `image-scale`. It must
|
|
155
307
|
finish before conversion, rather than running alongside the converter. No EPUB
|
|
156
308
|
postprocessing is needed. The earlier unreleased `epub image-width` prototype is
|
|
157
309
|
replaced by this document-based interface; it was not a released public command.
|
|
@@ -159,7 +311,7 @@ replaced by this document-based interface; it was not a released public command.
|
|
|
159
311
|
## Later scope
|
|
160
312
|
|
|
161
313
|
Image-file processing (`resize`, `trim`, `pad`, `quantize`, and possible composite
|
|
162
|
-
preparation) is planned for
|
|
314
|
+
preparation) is planned for a later release and tracked in
|
|
163
315
|
[GitHub issue #1](https://github.com/cybergarage/asciidoc-pubkit/issues/1).
|
|
164
|
-
Those commands are not implemented in v1.4.
|
|
316
|
+
Those commands are not implemented in v1.4.1. Their input will also be the
|
|
165
317
|
AsciiDoc document, rather than a standalone image.
|
data/docs/installation.md
CHANGED
|
@@ -8,7 +8,7 @@ asciidoc-pubkit --version
|
|
|
8
8
|
asciidoc-pubkit --help
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
The v1.4.
|
|
11
|
+
The v1.4.1 `image list`, `image stats` and `image scale` commands additionally
|
|
12
12
|
require ImageMagick 7 (`magick`) or 6 (`identify`). They do not require Python or
|
|
13
13
|
MeCab. See [image commands](image-commands.md).
|
|
14
14
|
|
data/lib/asciidoc_pubkit/cli.rb
CHANGED
|
@@ -15,8 +15,9 @@ module AsciidocPubkit
|
|
|
15
15
|
document check-xrefs FILE Report unresolved local cross-references
|
|
16
16
|
document index DIRECTORY Generate an English-title AsciiDoc index
|
|
17
17
|
image list FILE List images referenced by an AsciiDoc document
|
|
18
|
+
image find FILE Find document images by size, dimensions or aspect ratio
|
|
18
19
|
image stats FILE Summarize document-referenced image dimensions and sizes
|
|
19
|
-
image
|
|
20
|
+
image scale FILE Preview or explicitly apply display widths to source image macros
|
|
20
21
|
writing criteria Print the shared Japanese or English prose criteria
|
|
21
22
|
writing prompt Generate a technical writing prompt
|
|
22
23
|
review scan FILE Collect Japanese or English prose, headings, or list text and review candidates
|
|
@@ -34,7 +35,7 @@ module AsciidocPubkit
|
|
|
34
35
|
Use --lang ja (default) or en with writing commands and review commands. Other
|
|
35
36
|
languages and regional tags are unsupported and return an error.
|
|
36
37
|
skill install and upgrade write only the selected skill directory.
|
|
37
|
-
replace apply and image
|
|
38
|
+
replace apply and image scale --in-place explicitly edit manuscript sources. review score --agent explicitly invokes a
|
|
38
39
|
local Codex or Claude CLI, which may connect to its configured AI service.
|
|
39
40
|
TEXT
|
|
40
41
|
|
|
@@ -50,8 +50,8 @@ module AsciidocPubkit
|
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def self.run(command, args, out:, err:)
|
|
53
|
-
raise Error, 'Unknown image command. Use --help.' unless %w[list stats
|
|
54
|
-
options = { attributes: {}, exclude: [], ratio: 0.8, min: 40.0, max: 100.0 }
|
|
53
|
+
raise Error, 'Unknown image command. Use --help.' unless %w[list stats scale find].include?(command)
|
|
54
|
+
options = { attributes: {}, include: [], exclude: [], ratio: 0.8, min: 40.0, max: 100.0, mode: 'automatic', scale_factor: 0.9, height_factor: 1.0, area_factor: 0.8 }
|
|
55
55
|
parser = OptionParser.new do |opts|
|
|
56
56
|
opts.banner = "Usage: asciidoc-pubkit image #{command} DOCUMENT.adoc [options]"
|
|
57
57
|
opts.on('--base-dir DIR', 'Local include and image boundary (default: document directory)') { |v| options[:base_dir] = v }
|
|
@@ -62,13 +62,20 @@ module AsciidocPubkit
|
|
|
62
62
|
options[:attributes][key] = value || ''
|
|
63
63
|
end
|
|
64
64
|
opts.on('--only FILE', 'Select image references from one included source file') { |v| options[:only] = v }
|
|
65
|
+
opts.on('--include GLOB', 'Select matching image basename or document-relative path; repeatable') { |v| options[:include] << v }
|
|
65
66
|
opts.on('--exclude GLOB', 'Exclude image basename or document-relative path; repeatable') { |v| options[:exclude] << v }
|
|
66
67
|
opts.on('--include-artwork', 'Include block images matching default artwork exclusions') { options[:artwork] = true }
|
|
67
68
|
opts.on('--json', 'Print a structured report') { options[:json] = true }
|
|
68
|
-
if command == '
|
|
69
|
-
|
|
70
|
-
opts.on('--
|
|
71
|
-
opts.on('--
|
|
69
|
+
add_find_options(opts, options) if command == 'find'
|
|
70
|
+
if command == 'scale'
|
|
71
|
+
opts.on('--mode MODE', 'Sizing mode: automatic (default) or book') { |v| options[:mode] = v; options[:automatic_options] = true }
|
|
72
|
+
opts.on('--scale-factor NUMBER', Float, 'Book-mode overall multiplier (default: 0.9)') { |v| options[:scale_factor] = v; options[:book_options] = true }
|
|
73
|
+
opts.on('--height-factor NUMBER', Float, 'Book-mode median height multiplier (default: 1)') { |v| options[:height_factor] = v; options[:book_options] = true }
|
|
74
|
+
opts.on('--area-factor NUMBER', Float, 'Book-mode median area multiplier (default: 0.8)') { |v| options[:area_factor] = v; options[:book_options] = true }
|
|
75
|
+
opts.on('--width PERCENT', Float, 'Fixed scaledwidth percentage instead of automatic calculation') { |v| options[:width] = v }
|
|
76
|
+
opts.on('--height-width-ratio NUMBER', Float, 'Target image height / text width (default: 0.8)') { |v| options[:ratio] = v; options[:automatic_options] = true }
|
|
77
|
+
opts.on('--min-width PERCENT', Float, 'Minimum display width (default: 40)') { |v| options[:min] = v; options[:automatic_options] = true }
|
|
78
|
+
opts.on('--max-width PERCENT', Float, 'Maximum display width (default: 100)') { |v| options[:max] = v; options[:automatic_options] = true }
|
|
72
79
|
opts.on('--dry-run', 'Preview only (default)') { options[:dry_run] = true }
|
|
73
80
|
opts.on('--diff', 'Preview a unified source diff') { options[:diff] = true }
|
|
74
81
|
opts.on('--in-place', 'Explicitly update source image macros') { options[:in_place] = true }
|
|
@@ -82,7 +89,21 @@ module AsciidocPubkit
|
|
|
82
89
|
end
|
|
83
90
|
raise Error, 'Exactly one AsciiDoc document is required.' unless args.length == 1
|
|
84
91
|
raise Error, 'Expected an AsciiDoc document (.adoc or .asciidoc), not an image.' unless %w[.adoc .asciidoc].include?(File.extname(args.first).downcase)
|
|
85
|
-
if command == '
|
|
92
|
+
if command == 'scale'
|
|
93
|
+
raise Error, 'Mode must be automatic or book.' unless %w[automatic book].include?(options[:mode])
|
|
94
|
+
if options[:book_options] && (options[:mode] != 'book' || options[:width])
|
|
95
|
+
raise Error, 'Book factor options require --mode book without --width.'
|
|
96
|
+
end
|
|
97
|
+
if options[:mode] == 'book'
|
|
98
|
+
raise Error, '--only cannot be used with book mode; calibrate the entire selected image set.' if options[:only]
|
|
99
|
+
unless %i[scale_factor height_factor area_factor].all? { |key| options[key].finite? && options[key].positive? && options[key] <= 1 }
|
|
100
|
+
raise Error, 'Book factors must be finite and greater than 0 and at most 1.'
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
if options[:width]
|
|
104
|
+
raise Error, 'Require finite 0 < width <= 100.' unless options[:width].finite? && options[:width].positive? && options[:width] <= 100
|
|
105
|
+
raise Error, '--width cannot be combined with automatic sizing options.' if options[:automatic_options]
|
|
106
|
+
end
|
|
86
107
|
unless [options[:ratio], options[:min], options[:max]].all?(&:finite?) &&
|
|
87
108
|
options[:ratio].positive? && options[:min].positive? && options[:min] <= options[:max] && options[:max] <= 100
|
|
88
109
|
raise Error, 'Require finite ratio > 0 and 0 < min-width <= max-width <= 100.'
|
|
@@ -90,8 +111,9 @@ module AsciidocPubkit
|
|
|
90
111
|
raise Error, '--in-place cannot be combined with --dry-run or --diff.' if options[:in_place] && (options[:dry_run] || options[:diff])
|
|
91
112
|
raise Error, '--diff cannot be combined with --json.' if options[:diff] && options[:json]
|
|
92
113
|
end
|
|
114
|
+
validate_find_options(options) if command == 'find'
|
|
93
115
|
tool = new(args.first, options, err)
|
|
94
|
-
report = command == 'stats' ? tool.stats : command == '
|
|
116
|
+
report = command == 'stats' ? tool.stats : command == 'scale' ? tool.scale : command == 'find' ? tool.find : tool.report
|
|
95
117
|
if options[:diff]
|
|
96
118
|
out.write(tool.diff)
|
|
97
119
|
elsif options[:json]
|
|
@@ -102,6 +124,54 @@ module AsciidocPubkit
|
|
|
102
124
|
0
|
|
103
125
|
end
|
|
104
126
|
|
|
127
|
+
FIND_METRICS = {
|
|
128
|
+
'bytes' => 'bytes', 'pixels' => 'pixels', 'pixel-width' => 'width',
|
|
129
|
+
'pixel-height' => 'height', 'aspect-ratio' => 'aspect_ratio'
|
|
130
|
+
}.freeze
|
|
131
|
+
|
|
132
|
+
def self.add_find_options(opts, options)
|
|
133
|
+
options[:filters] = {}
|
|
134
|
+
FIND_METRICS.each_key do |metric|
|
|
135
|
+
%w[min max].each do |bound|
|
|
136
|
+
name = "#{bound}-#{metric}"
|
|
137
|
+
opts.on("--#{name} VALUE", "Inclusive #{bound}imum #{metric}") do |value|
|
|
138
|
+
parsed = if metric == 'bytes'
|
|
139
|
+
match = value.match(/\A([0-9]+)(B|KB|MB|KiB|MiB)?\z/)
|
|
140
|
+
raise Error, "Invalid byte size: #{value}" unless match
|
|
141
|
+
match[1].to_i * { nil => 1, 'B' => 1, 'KB' => 1000, 'MB' => 1000**2,
|
|
142
|
+
'KiB' => 1024, 'MiB' => 1024**2 }.fetch(match[2])
|
|
143
|
+
elsif metric == 'aspect-ratio'
|
|
144
|
+
Float(value)
|
|
145
|
+
else
|
|
146
|
+
raise Error, "#{name} must be a positive integer." unless value.match?(/\A[0-9]+\z/)
|
|
147
|
+
value.to_i
|
|
148
|
+
end
|
|
149
|
+
options[:filters][name] = parsed
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
opts.on('--portrait', 'Select height > width; exclude squares') { options[:portrait] = true }
|
|
154
|
+
opts.on('--landscape', 'Select width > height; exclude squares') { options[:landscape] = true }
|
|
155
|
+
opts.on('--sort METRIC', "Sort by #{FIND_METRICS.keys.join(', ')} (default: document order)") { |v| options[:sort] = v }
|
|
156
|
+
opts.on('--order ORDER', 'asc or desc (default with --sort: desc)') { |v| options[:order] = v }
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def self.validate_find_options(options)
|
|
160
|
+
raise Error, '--portrait and --landscape cannot be combined.' if options[:portrait] && options[:landscape]
|
|
161
|
+
raise Error, "Unknown sort metric: #{options[:sort]}" if options[:sort] && !FIND_METRICS.key?(options[:sort])
|
|
162
|
+
raise Error, 'Order must be asc or desc.' if options[:order] && !%w[asc desc].include?(options[:order])
|
|
163
|
+
raise Error, '--order requires --sort.' if options[:order] && !options[:sort]
|
|
164
|
+
options[:filters].each do |name, value|
|
|
165
|
+
unless value.finite? && (name.end_with?('-bytes') ? value >= 0 : value > 0)
|
|
166
|
+
raise Error, "#{name} must be finite and #{name.end_with?('-bytes') ? 'nonnegative' : 'positive'}."
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
FIND_METRICS.each_key do |metric|
|
|
170
|
+
lower, upper = options[:filters].values_at("min-#{metric}", "max-#{metric}")
|
|
171
|
+
raise Error, "min-#{metric} cannot exceed max-#{metric}." if lower && upper && lower > upper
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
105
175
|
def initialize(entry, options, err)
|
|
106
176
|
@options, @err = options, err
|
|
107
177
|
@entry = File.realpath(entry)
|
|
@@ -135,10 +205,13 @@ module AsciidocPubkit
|
|
|
135
205
|
path = resolve_image(target, directory)
|
|
136
206
|
reference['image'] = path
|
|
137
207
|
relative = Pathname.new(path).relative_path_from(Pathname.new(@root)).to_s
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
elsif options[:exclude].any? { |glob| File.fnmatch?(glob, File.basename(path)) || File.fnmatch?(glob, relative, File::FNM_PATHNAME | File::FNM_EXTGLOB) }
|
|
208
|
+
included = options.fetch(:include, []).any? { |glob| matches?(glob, path, relative) }
|
|
209
|
+
if options[:exclude].any? { |glob| matches?(glob, path, relative) }
|
|
141
210
|
reason = 'excluded by pattern'
|
|
211
|
+
elsif !options.fetch(:include, []).empty? && !included
|
|
212
|
+
reason = 'outside --include patterns'
|
|
213
|
+
elsif !included && !options[:artwork] && (covers.include?(path) || ARTWORK.any? { |glob| File.fnmatch?(glob, File.basename(path)) })
|
|
214
|
+
reason = 'artwork'
|
|
142
215
|
end
|
|
143
216
|
end
|
|
144
217
|
if reason
|
|
@@ -157,6 +230,10 @@ module AsciidocPubkit
|
|
|
157
230
|
end
|
|
158
231
|
end
|
|
159
232
|
|
|
233
|
+
def matches?(glob, path, relative)
|
|
234
|
+
File.fnmatch?(glob, File.basename(path)) || File.fnmatch?(glob, relative, File::FNM_PATHNAME | File::FNM_EXTGLOB)
|
|
235
|
+
end
|
|
236
|
+
|
|
160
237
|
def remote?(path)
|
|
161
238
|
Asciidoctor::Helpers.uriish?(path.to_s)
|
|
162
239
|
end
|
|
@@ -193,6 +270,30 @@ module AsciidocPubkit
|
|
|
193
270
|
'excluded' => @excluded, 'scope' => 'parsed block image macros; inline images are not included' }
|
|
194
271
|
end
|
|
195
272
|
|
|
273
|
+
def find
|
|
274
|
+
result = report
|
|
275
|
+
images = @images.values.map { |image| image.merge('pixels' => image['width'] * image['height']) }
|
|
276
|
+
images.select! do |image|
|
|
277
|
+
(!@options[:portrait] || image['height'] > image['width']) &&
|
|
278
|
+
(!@options[:landscape] || image['width'] > image['height']) &&
|
|
279
|
+
@options[:filters].all? do |name, threshold|
|
|
280
|
+
bound, metric = name.split('-', 2)
|
|
281
|
+
value = image.fetch(FIND_METRICS.fetch(metric))
|
|
282
|
+
bound == 'min' ? value >= threshold : value <= threshold
|
|
283
|
+
end
|
|
284
|
+
end
|
|
285
|
+
if @options[:sort]
|
|
286
|
+
key = FIND_METRICS.fetch(@options[:sort])
|
|
287
|
+
direction = @options[:order] == 'asc' ? 1 : -1
|
|
288
|
+
images = images.each_with_index.sort_by { |image, index| [direction * image[key], index] }.map(&:first)
|
|
289
|
+
end
|
|
290
|
+
result.merge('images' => images, 'selected_image_count' => result['image_count'],
|
|
291
|
+
'selected_reference_count' => result['reference_count'],
|
|
292
|
+
'image_count' => images.length, 'reference_count' => images.sum { |i| i['references'].length },
|
|
293
|
+
'filters' => @options[:filters].merge('portrait' => !!@options[:portrait], 'landscape' => !!@options[:landscape]),
|
|
294
|
+
'sort' => @options[:sort], 'order' => @options[:sort] && (@options[:order] || 'desc'))
|
|
295
|
+
end
|
|
296
|
+
|
|
196
297
|
def stats
|
|
197
298
|
result = report.reject { |key, _| key == 'images' }
|
|
198
299
|
result['total_bytes'] = @images.values.sum { |i| i['bytes'] }
|
|
@@ -254,12 +355,58 @@ module AsciidocPubkit
|
|
|
254
355
|
value.to_s.delete_suffix('.0')
|
|
255
356
|
end
|
|
256
357
|
|
|
257
|
-
def
|
|
358
|
+
def automatic_width(image)
|
|
359
|
+
raw = 100 * @options[:ratio] * image['aspect_ratio']
|
|
360
|
+
[[[[raw, @options[:min]].max, @options[:max]].min.round(1), @options[:min]].max, @options[:max]].min
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
def median(values)
|
|
364
|
+
return nil if values.empty?
|
|
365
|
+
values = values.sort
|
|
366
|
+
middle = values.length / 2
|
|
367
|
+
values.length.odd? ? values[middle] : (values[middle - 1] + values[middle]) / 2.0
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
def book_calibration
|
|
371
|
+
images = @images.values
|
|
372
|
+
heights = images.map { |i| automatic_width(i) / 100.0 / i['aspect_ratio'] }
|
|
373
|
+
areas = images.map { |i| (automatic_width(i) / 100.0)**2 / i['aspect_ratio'] }
|
|
374
|
+
height, area = median(heights), median(areas)
|
|
375
|
+
{ 'image_count' => images.length, 'median_height' => height, 'median_area' => area,
|
|
376
|
+
'height_cap' => height && height * @options[:height_factor],
|
|
377
|
+
'area_cap' => area && area * @options[:area_factor],
|
|
378
|
+
'scale_factor' => @options[:scale_factor], 'height_factor' => @options[:height_factor],
|
|
379
|
+
'area_factor' => @options[:area_factor], 'units' => 'height: text width; area: text width squared' }
|
|
380
|
+
end
|
|
381
|
+
|
|
382
|
+
def scale
|
|
258
383
|
desired = {}
|
|
384
|
+
book = @options[:mode] == 'book'
|
|
385
|
+
calibration = book_calibration if book
|
|
386
|
+
conflicts = []
|
|
259
387
|
@images.each_value do |image|
|
|
260
388
|
raw = 100 * @options[:ratio] * image['aspect_ratio']
|
|
261
|
-
|
|
262
|
-
|
|
389
|
+
baseline = automatic_width(image)
|
|
390
|
+
value = @options[:width] || baseline
|
|
391
|
+
image['width_percent'], image['minimum_limited'] = value, !@options[:width] && raw < @options[:min]
|
|
392
|
+
if book
|
|
393
|
+
ratio = image['aspect_ratio']
|
|
394
|
+
candidate = [baseline * @options[:scale_factor],
|
|
395
|
+
100 * calibration['height_cap'] * ratio,
|
|
396
|
+
100 * Math.sqrt(calibration['area_cap'] * ratio)].min.floor(1)
|
|
397
|
+
image['baseline_width_percent'] = baseline
|
|
398
|
+
image['proposed_width_percent'] = candidate
|
|
399
|
+
if candidate < @options[:min] || candidate <= 0
|
|
400
|
+
image['requires_review'] = true
|
|
401
|
+
conflicts << { 'image' => image['path'], 'proposed_width_percent' => candidate,
|
|
402
|
+
'min_width' => @options[:min], 'reason' => 'minimum width conflicts with book size budgets' }
|
|
403
|
+
next
|
|
404
|
+
end
|
|
405
|
+
value = candidate
|
|
406
|
+
image['width_percent'], image['minimum_limited'] = value, false
|
|
407
|
+
image['display_height'] = value / 100.0 / ratio
|
|
408
|
+
image['display_area'] = (value / 100.0)**2 / ratio
|
|
409
|
+
end
|
|
263
410
|
image['references'].each do |reference|
|
|
264
411
|
match = source_macro(reference)
|
|
265
412
|
raise Error, "Cannot safely map image macro: #{reference['file']}:#{reference['line']}" unless match
|
|
@@ -283,8 +430,16 @@ module AsciidocPubkit
|
|
|
283
430
|
changes.each { |c| lines[c['line'] - 1] = c['after'] }
|
|
284
431
|
@revised[file] = lines.join
|
|
285
432
|
end
|
|
433
|
+
if book && !conflicts.empty?
|
|
434
|
+
@err.puts "Book scaling: #{conflicts.length} image(s) require review; minimum width conflicts with size budgets. No source is changed in preview."
|
|
435
|
+
raise Error, 'Book scaling has unresolved size conflicts; no sources were changed. Lower --min-width or revise the selection/budgets, then preview again.' if @options[:in_place]
|
|
436
|
+
end
|
|
286
437
|
apply if @options[:in_place]
|
|
287
|
-
report.merge('settings' => { '
|
|
438
|
+
report.merge('settings' => { 'mode' => @options[:width] ? 'fixed' : (book ? 'book' : 'automatic'), 'width' => @options[:width],
|
|
439
|
+
'height_width_ratio' => @options[:width] ? nil : @options[:ratio],
|
|
440
|
+
'min_width' => @options[:width] ? nil : @options[:min],
|
|
441
|
+
'max_width' => @options[:width] ? nil : @options[:max] },
|
|
442
|
+
'calibration' => calibration, 'conflicts' => conflicts,
|
|
288
443
|
'changes' => @changes, 'changed_files' => @revised.keys, 'applied' => !!@options[:in_place])
|
|
289
444
|
end
|
|
290
445
|
|
|
@@ -349,15 +504,20 @@ module AsciidocPubkit
|
|
|
349
504
|
end
|
|
350
505
|
|
|
351
506
|
def format(command, result)
|
|
352
|
-
if command == '
|
|
507
|
+
if command == 'find'
|
|
508
|
+
result['images'].map do |image|
|
|
509
|
+
"#{image['path']}\t#{image['width']}x#{image['height']}\taspect=#{image['aspect_ratio'].round(4)}\tpixels=#{image['pixels']}\tbytes=#{image['bytes']}\treferences=#{image['references'].length}\n" +
|
|
510
|
+
image['references'].map { |ref| " #{ref['file'] || '(unmapped)'}:#{ref['line'] || '?'}\n" }.join
|
|
511
|
+
end.join + "Matched images: #{result['image_count']} / #{result['selected_image_count']}; matched references: #{result['reference_count']}; excluded: #{@excluded.length}\n"
|
|
512
|
+
elsif command == 'stats'
|
|
353
513
|
"Images: #{result['image_count']}; references: #{result['reference_count']}; bytes: #{result['total_bytes']}\n" +
|
|
354
514
|
%w[width height aspect_ratio bytes].map { |key| "#{key}: #{result[key].to_json}\n" }.join
|
|
355
515
|
else
|
|
356
516
|
result['images'].map do |image|
|
|
357
517
|
"#{image['path']}\t#{image['width']}x#{image['height']}\taspect=#{image['aspect_ratio'].round(4)}\tbytes=#{image['bytes']}\treferences=#{image['references'].length}" +
|
|
358
|
-
(command == '
|
|
518
|
+
(command == 'scale' ? "\twidth=#{number(image['width_percent'])}%#{image['requires_review'] ? ' (requires review; proposed width=' + number(image['proposed_width_percent']) + '%; source unchanged)' : ''}#{image['minimum_limited'] ? ' (minimum width reached; height may exceed target)' : ''}" : '') + "\n"
|
|
359
519
|
end.join + "Images: #{result['image_count']}; references: #{result['reference_count']}; excluded: #{@excluded.length}" +
|
|
360
|
-
(command == '
|
|
520
|
+
(command == 'scale' ? "; changes: #{@changes.length}; #{result['applied'] ? 'applied' : 'preview'}" : '') + "\n"
|
|
361
521
|
end
|
|
362
522
|
end
|
|
363
523
|
end
|
data/lib/asciidoc_pubkit.rb
CHANGED