Skip to content

Commit 6049a0d

Browse files
authored
Consistent split image ordering across OSes (#320)
1 parent a8d76c1 commit 6049a0d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

docs/tutorial.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
- Supported image file types: PNG, JPEG, bitmaps, WebP, and [more](https://docs.opencv.org/4.8.0/d4/da8/group__imgcodecs.html#imread).
88
- Images can be any size and ratio.
99
- Images are matched in alphanumerical order.
10+
- Note that this can lead to discrepancies between the order of file as seen in your file browser and the order of Split Images in AutoSplit.
11+
- Windows Explorer displays files in [Natural sort order](https://en.wikipedia.org/wiki/Natural_sort_order).
12+
- On UNIX-based systems, it depends on your file browser.
1013
- Recommended filenaming convention: `001_SplitName.png, 002_SplitName.png, 003_SplitName.png`...
1114
- Custom split image settings are handled in the filename. See how [here](#custom-split-image-settings).
1215
- To create split images, it is recommended to use AutoSplit's Take Screenshot button for accuracy. However, images can be created using any method including Print Screen and [Snipping Tool](https://support.microsoft.com/en-us/help/4027213/windows-10-open-snipping-tool-and-take-a-screenshot).

src/split_parser.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,18 @@ def __get_images_from_directory(directory: "StrPath"):
221221
Returns a list of AutoSplitImage parsed from a directory.
222222
Hidden files, system files and folders are silently ignored.
223223
"""
224-
file_paths = (
224+
file_paths = [
225225
os.path.join(directory, filename) # format: skip
226226
for filename in os.listdir(directory)
227-
)
228-
filtered_image_paths = (
227+
]
228+
filtered_image_paths = [
229229
image_path # format: skip
230230
for image_path in file_paths
231231
if is_user_file(image_path)
232-
)
232+
]
233+
# On Linux, os.listdir doesn't list files in alphanumerical order.
234+
# On Windows, os.listdir is already alphanumerical, but let's ensure consistency across OSes.
235+
filtered_image_paths.sort()
233236
return [AutoSplitImage(image_path) for image_path in filtered_image_paths]
234237

235238

0 commit comments

Comments
 (0)