epub-image-helper


Nameepub-image-helper JSON
Version 1.0.6 PyPI version JSON
download
home_pagehttps://github.com/changyy/epub-image-helper
SummaryThis tool allows you to easily convert specified photos and images into EPUB e-book format, making it accessible for family and friends. It can be used to create monthly or yearly photo collections for children and transform travel photos into e-books.
upload_time2024-01-07 14:26:18
maintainer
docs_urlNone
authorYuan-Yi Chang
requires_python>=3.10
license
keywords python epub image photo album pdf
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # epub-image-helper

[![PyPI](https://img.shields.io/pypi/v/epub-image-helper.svg)](https://pypi.org/project/epub-image-helper/)

This tool allows you to easily convert specified photos and images into EPUB e-book format, making it accessible for family and friends. It can be used to create monthly or yearly photo collections for children and transform travel photos into e-books.

## Note

```
% cat requirements.txt 
#EbookLib==0.18
#git+https://github.com/changyy/ebooklib.git@release#egg=EbookLib
#EbookLib @ git+https://github.com/changyy/ebooklib.git@release
EbookLib.changyy==0.18.2023.1221.0
lxml==4.9.3
Pillow==10.1.0
PyMuPDF==1.23.7
PyMuPDFb==1.23.7
six==1.16.0
```

This tool relies on the Python library `EbookLib` to create EPUB format files. 

However, currently, ebooklib v0.18 still has some features that need enhancement. Pull requests (PRs) have been created and are awaiting review by the original author. In the meantime, an alternative solution has been implemented using the ebooklib.changyy package. Once the required features for the future are integrated, it will be possible to switch back to the original ebooklib.

More info:

- https://github.com/aerkalov/ebooklib/pulls
  - https://github.com/aerkalov/ebooklib/pull/298
  - https://github.com/aerkalov/ebooklib/pull/297
- https://pypi.org/project/EbookLib.changyy/
- https://github.com/changyy/ebooklib/tree/release

---

# Quick test

## Convert a PDF file consisting entirely of images to an EPUB file consisting entirely of images

```
% epub-image-helper | jq -r '.version'
1.0.4
% mkdir /tmp/test-pdf-workdir
% ls /tmp/input.pdf 
/tmp/input.pdf
% python3 -c 'from epub_image_helper.testPdf2Epub import testPdf2Epub ; testPdf2Epub(inputFile="/tmp/input.pdf", outputFile="/tmp/output.epub", tmpWorkDir="/tmp/test-pdf-workdir")'
{
    "status": true,
...
    "output": {
        "path": "/tmp/output.epub",
        "size": 140028568,
        "sizeReadable": "133.54 MB",
        "imageCount": 0,
        "timeCost": [
            3.0279159545898438e-05,
            44.72491812705994,
            2.896683931350708
        ]
    },
    "error": [],
    "version": "1.0.4"
}
```

## Test image compression

```
% epub-image-helper | jq -r '.version'
1.0.4
% python3 -c 'from epub_image_helper.testImageCompression import testImageCompression; testImageCompression("/tmp/test-images")'
000.png
plan: png, 100: rawSize: 720749, newSize: 720749
plan: png, 95: rawSize: 720749, newSize: 923203
plan: png, 90: rawSize: 720749, newSize: 923203
plan: png, 85: rawSize: 720749, newSize: 923203
plan: jpg, 100: rawSize: 720749, newSize: 3012792
plan: jpg, 95: rawSize: 720749, newSize: 2023737
plan: jpg, 90: rawSize: 720749, newSize: 1557584
plan: jpg, 85: rawSize: 720749, newSize: 1310936
...
```

## Batch processing Usage

```
% epub-image-helper | jq -r '.version'
1.0.4
% tree  example    
example
├── 01-batch-image-to-epub
│   ├── image2epub.py
│   └── input.json
└── 02-batch-pdf-to-epub
    ├── input.json
    └── pdf2epub.py

3 directories, 4 files
```

### Pack your NAS photo albums

```
% cd example/01-batch-image-to-epub
% tree .
.
├── epub
├── image2epub.py
├── input.json
└── storage
    └── url
        ├── 001
        │   ├── 01.jpg
        │   ├── 02.jpg
        │   └── 03.jpg
        └── 002
            ├── 01.jpg
            ├── 02.jpg
            ├── 03.jpg
            ├── 04.jpg
            └── 05.jpg

6 directories, 10 files
% cat input.json
[
  { 
    "name": "MyPhotosA",
    "author": ["Author"],
    "books": [
      "https://localhost/001/A", 
      "https://localhost/002/B", 
      "https://localhost/003/C"
    ]
  },
  { 
    "name": "MyPhotosB",
    "author": ["Author"],
    "books": [
      "https://localhost/004/A", 
      "https://localhost/005/B", 
      "https://localhost/006/C"
    ]
  }
]
% python3 image2epub.py
...
% tree epub 
epub
└── MyPhotosA
    ├── MyPhotosA01.epub
    └── MyPhotosA02.epub

2 directories, 2 files
```

---

# Usage

```
% pip install epub-image-helper
% epub-image-helper
{
    "status": false,
    "input": {
        "output": "/tmp/test.epub",
        "bookConfig": "{}",
        "bookCover": "",
        "bookId": "20a3f61e-8c83-4fca-9846-afd5ffbf108a",
        "bookTitle": "Unknown",
        "bookAuthor": "Unknown",
        "epubcheck": false,
        "imageDir": [],
        "pickFirstImageToBeBookCover": false,
        "debug": false,
        "bookTableOfContent": [],
        "imageFormatConversionTable": {}
    },
    "output": {
        "path": null,
        "size": 0,
        "sizeReadable": null,
        "imageCount": 0,
        "timeCost": [
            5.9604644775390625e-06
        ]
    },
    "error": [
        "If both 'imageDir' and 'bookTableOfContent' are empty, please set at least one of them."
    ],
    "version": "1.0.0"
}

% epub-image-helper -h
usage: epub-image-helper [-h] [--output OUTPUT] [--bookConfig BOOKCONFIG] [--bookCover BOOKCOVER] [--bookTitle BOOKTITLE]
              [--bookId BOOKID] [--bookAuthor BOOKAUTHOR] [--pickFirstImageToBeBookCover] [--debug]
              [--epubcheck]
              [imageDir ...]

positional arguments:
  imageDir              the directory where the image file is located

options:
  -h, --help            show this help message and exit
  --output OUTPUT       output epub path
  --bookConfig BOOKCONFIG
                        a JSON config for EPUB builder. '@-' will read from stdin
  --bookCover BOOKCOVER
                        set a cover image for EPUB
  --bookTitle BOOKTITLE
                        set book title
  --bookId BOOKID       set book uuid info
  --bookAuthor BOOKAUTHOR
                        set book author info
  --pickFirstImageToBeBookCover
                        Select the first image as the book cover when the 'bookCover' parameter is not specified
  --debug               show bookConfig only
  --epubcheck           test output epub format via epubcheck command
```

## 1. From an image folder to an EPUB book

```
% tree 01-image-folder 
01-image-folder
├── 01.jpg
├── 02.jpg
└── 03.jpg

1 directory, 3 files

% epub-image-helper exmaple/01-image-folder 
{
    "status": true,
    "input": {
        "output": "/tmp/test.epub",
        "bookConfig": "{}",
        "bookCover": "",
        "bookId": "b717c302-b724-40aa-a9bf-dbe885b51bfb",
        "bookTitle": "Unknown",
        "bookAuthor": "Unknown",
        "epubcheck": false,
        "imageDir": [
            "exmaple/01-image-folder"
        ],
        "pickFirstImageToBeBookCover": false,
        "debug": false,
        "bookTableOfContent": [
            {
                "type": "imageDir",
                "name": "01-image-folder",
                "imageDir": "exmaple/01-image-folder"
            }
        ],
        "imageFormatConversionTable": {}
    },
    "output": {
        "path": "/tmp/test.epub",
        "size": 361025,
        "sizeReadable": "352.56 KB",
        "imageCount": 0,
        "timeCost": [
            5.221366882324219e-05,
            5.1021575927734375e-05,
            0.012903928756713867
        ]
    },
    "error": [],
    "version": "1.0.0"
}

% unzip -l /tmp/test.epub 
Archive:  /tmp/test.epub
  Length      Date    Time    Name
---------  ---------- -----   ----
       20  12-17-2023 10:32   mimetype
      251  12-17-2023 10:32   META-INF/container.xml
     1802  12-17-2023 10:32   EPUB/content.opf
       55  12-17-2023 10:32   EPUB/default.css
   128903  12-17-2023 10:32   EPUB/img-1-000002.jpg
      619  12-17-2023 10:32   EPUB/xhtml-1-000003.xhtml
    88590  12-17-2023 10:32   EPUB/img-1-000004.jpg
      619  12-17-2023 10:32   EPUB/xhtml-1-000005.xhtml
   142203  12-17-2023 10:32   EPUB/img-1-000006.jpg
      620  12-17-2023 10:32   EPUB/xhtml-1-000007.xhtml
      411  12-17-2023 10:32   EPUB/toc.ncx
      333  12-17-2023 10:32   EPUB/nav.xhtml
---------                     -------
   364426                     12 files
```

## 2. From multiple image folders to an EPUB book

```
% tree 02-multiple-image-folders 
02-multiple-image-folders
├── first
│   ├── 01.jpg
│   ├── 02.jpg
│   └── 03.jpg
└── second
    ├── 01.jpg
    ├── 02.jpg
    ├── 03.jpg
    ├── 04.jpg
    └── 05.jpg

3 directories, 8 files

% epub-image-helper 02-multiple-image-folders
{
    "status": true,
    "input": {
        "output": "/tmp/test.epub",
        "bookConfig": "{}",
        "bookCover": "",
        "bookId": "011af0b8-0340-4f5d-b22a-10dbc0a52eea",
        "bookTitle": "Unknown",
        "bookAuthor": "Unknown",
        "epubcheck": false,
        "imageDir": [
            "exmaple/02-multiple-image-folders"
        ],
        "pickFirstImageToBeBookCover": false,
        "debug": false,
        "bookTableOfContent": [
            {
                "type": "imageDir",
                "name": "02-multiple-image-folders",
                "imageDir": "exmaple/02-multiple-image-folders"
            }
        ],
        "imageFormatConversionTable": {}
    },
    "output": {
        "path": "/tmp/test.epub",
        "size": 26444959,
        "sizeReadable": "25.22 MB",
        "imageCount": 0,
        "timeCost": [
            4.696846008300781e-05,
            0.00010395050048828125,
            0.5822200775146484
        ]
    },
    "error": [],
    "version": "1.0.0"
}

% unzip -l /tmp/test.epub 
Archive:  /tmp/test.epub
  Length      Date    Time    Name
---------  ---------- -----   ----
       20  12-17-2023 10:57   mimetype
      251  12-17-2023 10:57   META-INF/container.xml
     2807  12-17-2023 10:57   EPUB/content.opf
       55  12-17-2023 10:57   EPUB/default.css
   128903  12-17-2023 10:57   EPUB/img-1-000002.jpg
      629  12-17-2023 10:57   EPUB/xhtml-1-000003.xhtml
    88590  12-17-2023 10:57   EPUB/img-1-000004.jpg
      629  12-17-2023 10:57   EPUB/xhtml-1-000005.xhtml
   142203  12-17-2023 10:57   EPUB/img-1-000006.jpg
      629  12-17-2023 10:57   EPUB/xhtml-1-000007.xhtml
 11474510  12-17-2023 10:57   EPUB/img-1-000008.jpg
      631  12-17-2023 10:57   EPUB/xhtml-1-000009.xhtml
  6709355  12-17-2023 10:57   EPUB/img-1-000010.jpg
      631  12-17-2023 10:57   EPUB/xhtml-1-000011.xhtml
  2372710  12-17-2023 10:57   EPUB/img-1-000012.jpg
      631  12-17-2023 10:57   EPUB/xhtml-1-000013.xhtml
  5484157  12-17-2023 10:57   EPUB/img-1-000014.jpg
      631  12-17-2023 10:57   EPUB/xhtml-1-000015.xhtml
   114318  12-17-2023 10:57   EPUB/img-1-000016.jpg
      630  12-17-2023 10:57   EPUB/xhtml-1-000017.xhtml
      411  12-17-2023 10:57   EPUB/toc.ncx
      333  12-17-2023 10:57   EPUB/nav.xhtml
---------                     -------
 26523664                     22 files
```

---

```
% epub-image-helper 02-multiple-image-folders/first 02-multiple-image-folders/second 
{
    "status": true,
    "input": {
        "output": "/tmp/test.epub",
        "bookConfig": "{}",
        "bookCover": "",
        "bookId": "5026a99b-257b-4c1d-bb51-d4c2fc6e3610",
        "bookTitle": "Unknown",
        "bookAuthor": "Unknown",
        "epubcheck": false,
        "imageDir": [
            "exmaple/02-multiple-image-folders/first",
            "exmaple/02-multiple-image-folders/second"
        ],
        "pickFirstImageToBeBookCover": false,
        "debug": false,
        "bookTableOfContent": [
            {
                "type": "imageDir",
                "name": "first",
                "imageDir": "exmaple/02-multiple-image-folders/first"
            },
            {
                "type": "imageDir",
                "name": "second",
                "imageDir": "exmaple/02-multiple-image-folders/second"
            }
        ],
        "imageFormatConversionTable": {}
    },
    "output": {
        "path": "/tmp/test.epub",
        "size": 26444875,
        "sizeReadable": "25.22 MB",
        "imageCount": 0,
        "timeCost": [
            5.984306335449219e-05,
            7.414817810058594e-05,
            0.5851681232452393
        ]
    },
    "error": [],
    "version": "1.0.0"
}

% unzip -l /tmp/test.epub 
Archive:  /tmp/test.epub
  Length      Date    Time    Name
---------  ---------- -----   ----
       20  12-17-2023 11:01   mimetype
      251  12-17-2023 11:01   META-INF/container.xml
     2807  12-17-2023 11:01   EPUB/content.opf
       55  12-17-2023 11:01   EPUB/default.css
   128903  12-17-2023 11:01   EPUB/img-1-000002.jpg
      609  12-17-2023 11:01   EPUB/xhtml-1-000003.xhtml
    88590  12-17-2023 11:01   EPUB/img-1-000004.jpg
      609  12-17-2023 11:01   EPUB/xhtml-1-000005.xhtml
   142203  12-17-2023 11:01   EPUB/img-1-000006.jpg
      610  12-17-2023 11:01   EPUB/xhtml-1-000007.xhtml
 11474510  12-17-2023 11:01   EPUB/img-2-000008.jpg
      612  12-17-2023 11:01   EPUB/xhtml-2-000009.xhtml
  6709355  12-17-2023 11:01   EPUB/img-2-000010.jpg
      612  12-17-2023 11:01   EPUB/xhtml-2-000011.xhtml
  2372710  12-17-2023 11:01   EPUB/img-2-000012.jpg
      612  12-17-2023 11:01   EPUB/xhtml-2-000013.xhtml
  5484157  12-17-2023 11:01   EPUB/img-2-000014.jpg
      612  12-17-2023 11:01   EPUB/xhtml-2-000015.xhtml
   114318  12-17-2023 11:01   EPUB/img-2-000016.jpg
      611  12-17-2023 11:01   EPUB/xhtml-2-000017.xhtml
      411  12-17-2023 11:01   EPUB/toc.ncx
      333  12-17-2023 11:01   EPUB/nav.xhtml
---------                     -------
 26523510                     22 files
```

## 2. Convert all images from a PDF file to an EPUB file.

```
% pdfinfo /tmp/test.pdf | grep Pages
Pages:           3

% echo '{"bookTableOfContent": [ { "type": "imagePdf", "name": "Test", "imagePdf": "/tmp/test.pdf", "workDir": "/tmp/workDir-test.pdf", "imagePdfSaveFormat": "jpg" , "imagePdfSaveQuality": 100 } ]}' | epub-image-helper --bookConfig @-
{
    "status": false,
    "input": {
        "output": "/tmp/test.epub",
        "bookConfig": "@-",
        "bookCover": "",
        "bookId": "438e9899-eafc-42ef-bc21-c0134c4f82f4",
        "bookTitle": "Unknown",
        "bookAuthor": "Unknown",
        "epubcheck": false,
        "imageDir": [],
        "pickFirstImageToBeBookCover": false,
        "debug": false,
        "bookTableOfContent": [
            {
                "type": "imagePdf",
                "name": "Test",
                "imagePdf": "/tmp/test.pdf",
                "workDir": "/tmp/workDir-test.pdf",
                "imagePdfSaveFormat": "jpg",
                "imagePdfSaveQuality": 100
            }
        ],
        "imageFormatConversionTable": {},
        "stdin": "{\"bookTableOfContent\": [ { \"type\": \"imagePdf\", \"name\": \"Test\", \"imagePdf\": \"/tmp/test.pdf\", \"workDir\": \"/tmp/workDir-test.pdf\", \"imagePdfSaveFormat\": \"jpg\" , \"imagePdfSaveQuality\": 100 } ]}\n"
    },
    "output": {
        "path": null,
        "size": 0,
        "sizeReadable": null,
        "imageCount": 0,
        "timeCost": [
            2.9087066650390625e-05,
            3.0279159545898438e-05
        ]
    },
    "error": [
        {
            "status": false,
            "error": [
                "type=\"imagePdf\" error, \"workDir\" not exists: index=0, item={'type': 'imagePdf', 'name': 'Test', 'imagePdf': '/tmp/test.pdf', 'workDir': '/tmp/workDir-test.pdf', 'imagePdfSaveFormat': 'jpg', 'imagePdfSaveQuality': 100}"
            ],
            "input": [
                {
                    "type": "imagePdf",
                    "name": "Test",
                    "imagePdf": "/tmp/test.pdf",
                    "workDir": "/tmp/workDir-test.pdf",
                    "imagePdfSaveFormat": "jpg",
                    "imagePdfSaveQuality": 100
                }
            ],
            "output": [],
            "totalImage": 0,
            "timeCost": []
        }
    ],
    "version": "1.0.0"
}

% mkdir /tmp/workDir-test.pdf

% echo '{"bookTableOfContent": [ { "type": "imagePdf", "name": "Test", "imagePdf": "/tmp/test.pdf", "workDir": "/tmp/workDir-test.pdf", "imagePdfSaveFormat": "jpg" , "imagePdfSaveQuality": 100 } ]}' | epub-image-helper --bookConfig @-
{
    "status": true,
    "input": {
        "output": "/tmp/test.epub",
        "bookConfig": "@-",
        "bookCover": "",
        "bookId": "1e788bee-4f66-49f5-bce3-c412a7a4a348",
        "bookTitle": "Unknown",
        "bookAuthor": "Unknown",
        "epubcheck": false,
        "imageDir": [],
        "pickFirstImageToBeBookCover": false,
        "debug": false,
        "bookTableOfContent": [
            {
                "type": "imagePdf",
                "name": "Test",
                "imagePdf": "/tmp/test.pdf",
                "workDir": "/tmp/workDir-test.pdf",
                "imagePdfSaveFormat": "jpg",
                "imagePdfSaveQuality": 100
            }
        ],
        "imageFormatConversionTable": {},
        "stdin": "{\"bookTableOfContent\": [ { \"type\": \"imagePdf\", \"name\": \"Test\", \"imagePdf\": \"/tmp/test.pdf\", \"workDir\": \"/tmp/workDir-test.pdf\", \"imagePdfSaveFormat\": \"jpg\" , \"imagePdfSaveQuality\": 100 } ]}\n"
    },
    "output": {
        "path": "/tmp/test.epub",
        "size": 361006,
        "sizeReadable": "352.54 KB",
        "imageCount": 0,
        "timeCost": [
            3.0994415283203125e-05,
            0.035225868225097656,
            0.013682126998901367
        ]
    },
    "error": [],
    "version": "1.0.0"
}

% unzip -l /tmp/test.epub 
Archive:  /tmp/test.epub
  Length      Date    Time    Name
---------  ---------- -----   ----
       20  12-17-2023 13:37   mimetype
      251  12-17-2023 13:37   META-INF/container.xml
     1802  12-17-2023 13:37   EPUB/content.opf
       55  12-17-2023 13:37   EPUB/default.css
   128903  12-17-2023 13:37   EPUB/img-1-000002.jpg
      608  12-17-2023 13:37   EPUB/xhtml-1-000003.xhtml
    88590  12-17-2023 13:37   EPUB/img-1-000004.jpg
      608  12-17-2023 13:37   EPUB/xhtml-1-000005.xhtml
   142203  12-17-2023 13:37   EPUB/img-1-000006.jpg
      609  12-17-2023 13:37   EPUB/xhtml-1-000007.xhtml
      411  12-17-2023 13:37   EPUB/toc.ncx
      333  12-17-2023 13:37   EPUB/nav.xhtml
---------                     -------
   364393                     12 files
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/changyy/epub-image-helper",
    "name": "epub-image-helper",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "python,epub,image,photo,album,pdf",
    "author": "Yuan-Yi Chang",
    "author_email": "<changyy.csie@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/44/56/091f74863f20950e21a932b87e727613270e07a44e4406adebf62b084ba8/epub-image-helper-1.0.6.tar.gz",
    "platform": null,
    "description": "# epub-image-helper\n\n[![PyPI](https://img.shields.io/pypi/v/epub-image-helper.svg)](https://pypi.org/project/epub-image-helper/)\n\nThis tool allows you to easily convert specified photos and images into EPUB e-book format, making it accessible for family and friends. It can be used to create monthly or yearly photo collections for children and transform travel photos into e-books.\n\n## Note\n\n```\n% cat requirements.txt \n#EbookLib==0.18\n#git+https://github.com/changyy/ebooklib.git@release#egg=EbookLib\n#EbookLib @ git+https://github.com/changyy/ebooklib.git@release\nEbookLib.changyy==0.18.2023.1221.0\nlxml==4.9.3\nPillow==10.1.0\nPyMuPDF==1.23.7\nPyMuPDFb==1.23.7\nsix==1.16.0\n```\n\nThis tool relies on the Python library `EbookLib` to create EPUB format files. \n\nHowever, currently, ebooklib v0.18 still has some features that need enhancement. Pull requests (PRs) have been created and are awaiting review by the original author. In the meantime, an alternative solution has been implemented using the ebooklib.changyy package. Once the required features for the future are integrated, it will be possible to switch back to the original ebooklib.\n\nMore info:\n\n- https://github.com/aerkalov/ebooklib/pulls\n  - https://github.com/aerkalov/ebooklib/pull/298\n  - https://github.com/aerkalov/ebooklib/pull/297\n- https://pypi.org/project/EbookLib.changyy/\n- https://github.com/changyy/ebooklib/tree/release\n\n---\n\n# Quick test\n\n## Convert a PDF file consisting entirely of images to an EPUB file consisting entirely of images\n\n```\n% epub-image-helper | jq -r '.version'\n1.0.4\n% mkdir /tmp/test-pdf-workdir\n% ls /tmp/input.pdf \n/tmp/input.pdf\n% python3 -c 'from epub_image_helper.testPdf2Epub import testPdf2Epub ; testPdf2Epub(inputFile=\"/tmp/input.pdf\", outputFile=\"/tmp/output.epub\", tmpWorkDir=\"/tmp/test-pdf-workdir\")'\n{\n    \"status\": true,\n...\n    \"output\": {\n        \"path\": \"/tmp/output.epub\",\n        \"size\": 140028568,\n        \"sizeReadable\": \"133.54 MB\",\n        \"imageCount\": 0,\n        \"timeCost\": [\n            3.0279159545898438e-05,\n            44.72491812705994,\n            2.896683931350708\n        ]\n    },\n    \"error\": [],\n    \"version\": \"1.0.4\"\n}\n```\n\n## Test image compression\n\n```\n% epub-image-helper | jq -r '.version'\n1.0.4\n% python3 -c 'from epub_image_helper.testImageCompression import testImageCompression; testImageCompression(\"/tmp/test-images\")'\n000.png\nplan: png, 100: rawSize: 720749, newSize: 720749\nplan: png, 95: rawSize: 720749, newSize: 923203\nplan: png, 90: rawSize: 720749, newSize: 923203\nplan: png, 85: rawSize: 720749, newSize: 923203\nplan: jpg, 100: rawSize: 720749, newSize: 3012792\nplan: jpg, 95: rawSize: 720749, newSize: 2023737\nplan: jpg, 90: rawSize: 720749, newSize: 1557584\nplan: jpg, 85: rawSize: 720749, newSize: 1310936\n...\n```\n\n## Batch processing Usage\n\n```\n% epub-image-helper | jq -r '.version'\n1.0.4\n% tree  example    \nexample\n\u251c\u2500\u2500 01-batch-image-to-epub\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 image2epub.py\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 input.json\n\u2514\u2500\u2500 02-batch-pdf-to-epub\n    \u251c\u2500\u2500 input.json\n    \u2514\u2500\u2500 pdf2epub.py\n\n3 directories, 4 files\n```\n\n### Pack your NAS photo albums\n\n```\n% cd example/01-batch-image-to-epub\n% tree .\n.\n\u251c\u2500\u2500 epub\n\u251c\u2500\u2500 image2epub.py\n\u251c\u2500\u2500 input.json\n\u2514\u2500\u2500 storage\n    \u2514\u2500\u2500 url\n        \u251c\u2500\u2500 001\n        \u2502\u00a0\u00a0 \u251c\u2500\u2500 01.jpg\n        \u2502\u00a0\u00a0 \u251c\u2500\u2500 02.jpg\n        \u2502\u00a0\u00a0 \u2514\u2500\u2500 03.jpg\n        \u2514\u2500\u2500 002\n            \u251c\u2500\u2500 01.jpg\n            \u251c\u2500\u2500 02.jpg\n            \u251c\u2500\u2500 03.jpg\n            \u251c\u2500\u2500 04.jpg\n            \u2514\u2500\u2500 05.jpg\n\n6 directories, 10 files\n% cat input.json\n[\n  { \n    \"name\": \"MyPhotosA\",\n    \"author\": [\"Author\"],\n    \"books\": [\n      \"https://localhost/001/A\", \n      \"https://localhost/002/B\", \n      \"https://localhost/003/C\"\n    ]\n  },\n  { \n    \"name\": \"MyPhotosB\",\n    \"author\": [\"Author\"],\n    \"books\": [\n      \"https://localhost/004/A\", \n      \"https://localhost/005/B\", \n      \"https://localhost/006/C\"\n    ]\n  }\n]\n% python3 image2epub.py\n...\n% tree epub \nepub\n\u2514\u2500\u2500 MyPhotosA\n    \u251c\u2500\u2500 MyPhotosA01.epub\n    \u2514\u2500\u2500 MyPhotosA02.epub\n\n2 directories, 2 files\n```\n\n---\n\n# Usage\n\n```\n% pip install epub-image-helper\n% epub-image-helper\n{\n    \"status\": false,\n    \"input\": {\n        \"output\": \"/tmp/test.epub\",\n        \"bookConfig\": \"{}\",\n        \"bookCover\": \"\",\n        \"bookId\": \"20a3f61e-8c83-4fca-9846-afd5ffbf108a\",\n        \"bookTitle\": \"Unknown\",\n        \"bookAuthor\": \"Unknown\",\n        \"epubcheck\": false,\n        \"imageDir\": [],\n        \"pickFirstImageToBeBookCover\": false,\n        \"debug\": false,\n        \"bookTableOfContent\": [],\n        \"imageFormatConversionTable\": {}\n    },\n    \"output\": {\n        \"path\": null,\n        \"size\": 0,\n        \"sizeReadable\": null,\n        \"imageCount\": 0,\n        \"timeCost\": [\n            5.9604644775390625e-06\n        ]\n    },\n    \"error\": [\n        \"If both 'imageDir' and 'bookTableOfContent' are empty, please set at least one of them.\"\n    ],\n    \"version\": \"1.0.0\"\n}\n\n% epub-image-helper -h\nusage: epub-image-helper [-h] [--output OUTPUT] [--bookConfig BOOKCONFIG] [--bookCover BOOKCOVER] [--bookTitle BOOKTITLE]\n              [--bookId BOOKID] [--bookAuthor BOOKAUTHOR] [--pickFirstImageToBeBookCover] [--debug]\n              [--epubcheck]\n              [imageDir ...]\n\npositional arguments:\n  imageDir              the directory where the image file is located\n\noptions:\n  -h, --help            show this help message and exit\n  --output OUTPUT       output epub path\n  --bookConfig BOOKCONFIG\n                        a JSON config for EPUB builder. '@-' will read from stdin\n  --bookCover BOOKCOVER\n                        set a cover image for EPUB\n  --bookTitle BOOKTITLE\n                        set book title\n  --bookId BOOKID       set book uuid info\n  --bookAuthor BOOKAUTHOR\n                        set book author info\n  --pickFirstImageToBeBookCover\n                        Select the first image as the book cover when the 'bookCover' parameter is not specified\n  --debug               show bookConfig only\n  --epubcheck           test output epub format via epubcheck command\n```\n\n## 1. From an image folder to an EPUB book\n\n```\n% tree 01-image-folder \n01-image-folder\n\u251c\u2500\u2500 01.jpg\n\u251c\u2500\u2500 02.jpg\n\u2514\u2500\u2500 03.jpg\n\n1 directory, 3 files\n\n% epub-image-helper exmaple/01-image-folder \n{\n    \"status\": true,\n    \"input\": {\n        \"output\": \"/tmp/test.epub\",\n        \"bookConfig\": \"{}\",\n        \"bookCover\": \"\",\n        \"bookId\": \"b717c302-b724-40aa-a9bf-dbe885b51bfb\",\n        \"bookTitle\": \"Unknown\",\n        \"bookAuthor\": \"Unknown\",\n        \"epubcheck\": false,\n        \"imageDir\": [\n            \"exmaple/01-image-folder\"\n        ],\n        \"pickFirstImageToBeBookCover\": false,\n        \"debug\": false,\n        \"bookTableOfContent\": [\n            {\n                \"type\": \"imageDir\",\n                \"name\": \"01-image-folder\",\n                \"imageDir\": \"exmaple/01-image-folder\"\n            }\n        ],\n        \"imageFormatConversionTable\": {}\n    },\n    \"output\": {\n        \"path\": \"/tmp/test.epub\",\n        \"size\": 361025,\n        \"sizeReadable\": \"352.56 KB\",\n        \"imageCount\": 0,\n        \"timeCost\": [\n            5.221366882324219e-05,\n            5.1021575927734375e-05,\n            0.012903928756713867\n        ]\n    },\n    \"error\": [],\n    \"version\": \"1.0.0\"\n}\n\n% unzip -l /tmp/test.epub \nArchive:  /tmp/test.epub\n  Length      Date    Time    Name\n---------  ---------- -----   ----\n       20  12-17-2023 10:32   mimetype\n      251  12-17-2023 10:32   META-INF/container.xml\n     1802  12-17-2023 10:32   EPUB/content.opf\n       55  12-17-2023 10:32   EPUB/default.css\n   128903  12-17-2023 10:32   EPUB/img-1-000002.jpg\n      619  12-17-2023 10:32   EPUB/xhtml-1-000003.xhtml\n    88590  12-17-2023 10:32   EPUB/img-1-000004.jpg\n      619  12-17-2023 10:32   EPUB/xhtml-1-000005.xhtml\n   142203  12-17-2023 10:32   EPUB/img-1-000006.jpg\n      620  12-17-2023 10:32   EPUB/xhtml-1-000007.xhtml\n      411  12-17-2023 10:32   EPUB/toc.ncx\n      333  12-17-2023 10:32   EPUB/nav.xhtml\n---------                     -------\n   364426                     12 files\n```\n\n## 2. From multiple image folders to an EPUB book\n\n```\n% tree 02-multiple-image-folders \n02-multiple-image-folders\n\u251c\u2500\u2500 first\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 01.jpg\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 02.jpg\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 03.jpg\n\u2514\u2500\u2500 second\n    \u251c\u2500\u2500 01.jpg\n    \u251c\u2500\u2500 02.jpg\n    \u251c\u2500\u2500 03.jpg\n    \u251c\u2500\u2500 04.jpg\n    \u2514\u2500\u2500 05.jpg\n\n3 directories, 8 files\n\n% epub-image-helper 02-multiple-image-folders\n{\n    \"status\": true,\n    \"input\": {\n        \"output\": \"/tmp/test.epub\",\n        \"bookConfig\": \"{}\",\n        \"bookCover\": \"\",\n        \"bookId\": \"011af0b8-0340-4f5d-b22a-10dbc0a52eea\",\n        \"bookTitle\": \"Unknown\",\n        \"bookAuthor\": \"Unknown\",\n        \"epubcheck\": false,\n        \"imageDir\": [\n            \"exmaple/02-multiple-image-folders\"\n        ],\n        \"pickFirstImageToBeBookCover\": false,\n        \"debug\": false,\n        \"bookTableOfContent\": [\n            {\n                \"type\": \"imageDir\",\n                \"name\": \"02-multiple-image-folders\",\n                \"imageDir\": \"exmaple/02-multiple-image-folders\"\n            }\n        ],\n        \"imageFormatConversionTable\": {}\n    },\n    \"output\": {\n        \"path\": \"/tmp/test.epub\",\n        \"size\": 26444959,\n        \"sizeReadable\": \"25.22 MB\",\n        \"imageCount\": 0,\n        \"timeCost\": [\n            4.696846008300781e-05,\n            0.00010395050048828125,\n            0.5822200775146484\n        ]\n    },\n    \"error\": [],\n    \"version\": \"1.0.0\"\n}\n\n% unzip -l /tmp/test.epub \nArchive:  /tmp/test.epub\n  Length      Date    Time    Name\n---------  ---------- -----   ----\n       20  12-17-2023 10:57   mimetype\n      251  12-17-2023 10:57   META-INF/container.xml\n     2807  12-17-2023 10:57   EPUB/content.opf\n       55  12-17-2023 10:57   EPUB/default.css\n   128903  12-17-2023 10:57   EPUB/img-1-000002.jpg\n      629  12-17-2023 10:57   EPUB/xhtml-1-000003.xhtml\n    88590  12-17-2023 10:57   EPUB/img-1-000004.jpg\n      629  12-17-2023 10:57   EPUB/xhtml-1-000005.xhtml\n   142203  12-17-2023 10:57   EPUB/img-1-000006.jpg\n      629  12-17-2023 10:57   EPUB/xhtml-1-000007.xhtml\n 11474510  12-17-2023 10:57   EPUB/img-1-000008.jpg\n      631  12-17-2023 10:57   EPUB/xhtml-1-000009.xhtml\n  6709355  12-17-2023 10:57   EPUB/img-1-000010.jpg\n      631  12-17-2023 10:57   EPUB/xhtml-1-000011.xhtml\n  2372710  12-17-2023 10:57   EPUB/img-1-000012.jpg\n      631  12-17-2023 10:57   EPUB/xhtml-1-000013.xhtml\n  5484157  12-17-2023 10:57   EPUB/img-1-000014.jpg\n      631  12-17-2023 10:57   EPUB/xhtml-1-000015.xhtml\n   114318  12-17-2023 10:57   EPUB/img-1-000016.jpg\n      630  12-17-2023 10:57   EPUB/xhtml-1-000017.xhtml\n      411  12-17-2023 10:57   EPUB/toc.ncx\n      333  12-17-2023 10:57   EPUB/nav.xhtml\n---------                     -------\n 26523664                     22 files\n```\n\n---\n\n```\n% epub-image-helper 02-multiple-image-folders/first 02-multiple-image-folders/second \n{\n    \"status\": true,\n    \"input\": {\n        \"output\": \"/tmp/test.epub\",\n        \"bookConfig\": \"{}\",\n        \"bookCover\": \"\",\n        \"bookId\": \"5026a99b-257b-4c1d-bb51-d4c2fc6e3610\",\n        \"bookTitle\": \"Unknown\",\n        \"bookAuthor\": \"Unknown\",\n        \"epubcheck\": false,\n        \"imageDir\": [\n            \"exmaple/02-multiple-image-folders/first\",\n            \"exmaple/02-multiple-image-folders/second\"\n        ],\n        \"pickFirstImageToBeBookCover\": false,\n        \"debug\": false,\n        \"bookTableOfContent\": [\n            {\n                \"type\": \"imageDir\",\n                \"name\": \"first\",\n                \"imageDir\": \"exmaple/02-multiple-image-folders/first\"\n            },\n            {\n                \"type\": \"imageDir\",\n                \"name\": \"second\",\n                \"imageDir\": \"exmaple/02-multiple-image-folders/second\"\n            }\n        ],\n        \"imageFormatConversionTable\": {}\n    },\n    \"output\": {\n        \"path\": \"/tmp/test.epub\",\n        \"size\": 26444875,\n        \"sizeReadable\": \"25.22 MB\",\n        \"imageCount\": 0,\n        \"timeCost\": [\n            5.984306335449219e-05,\n            7.414817810058594e-05,\n            0.5851681232452393\n        ]\n    },\n    \"error\": [],\n    \"version\": \"1.0.0\"\n}\n\n% unzip -l /tmp/test.epub \nArchive:  /tmp/test.epub\n  Length      Date    Time    Name\n---------  ---------- -----   ----\n       20  12-17-2023 11:01   mimetype\n      251  12-17-2023 11:01   META-INF/container.xml\n     2807  12-17-2023 11:01   EPUB/content.opf\n       55  12-17-2023 11:01   EPUB/default.css\n   128903  12-17-2023 11:01   EPUB/img-1-000002.jpg\n      609  12-17-2023 11:01   EPUB/xhtml-1-000003.xhtml\n    88590  12-17-2023 11:01   EPUB/img-1-000004.jpg\n      609  12-17-2023 11:01   EPUB/xhtml-1-000005.xhtml\n   142203  12-17-2023 11:01   EPUB/img-1-000006.jpg\n      610  12-17-2023 11:01   EPUB/xhtml-1-000007.xhtml\n 11474510  12-17-2023 11:01   EPUB/img-2-000008.jpg\n      612  12-17-2023 11:01   EPUB/xhtml-2-000009.xhtml\n  6709355  12-17-2023 11:01   EPUB/img-2-000010.jpg\n      612  12-17-2023 11:01   EPUB/xhtml-2-000011.xhtml\n  2372710  12-17-2023 11:01   EPUB/img-2-000012.jpg\n      612  12-17-2023 11:01   EPUB/xhtml-2-000013.xhtml\n  5484157  12-17-2023 11:01   EPUB/img-2-000014.jpg\n      612  12-17-2023 11:01   EPUB/xhtml-2-000015.xhtml\n   114318  12-17-2023 11:01   EPUB/img-2-000016.jpg\n      611  12-17-2023 11:01   EPUB/xhtml-2-000017.xhtml\n      411  12-17-2023 11:01   EPUB/toc.ncx\n      333  12-17-2023 11:01   EPUB/nav.xhtml\n---------                     -------\n 26523510                     22 files\n```\n\n## 2. Convert all images from a PDF file to an EPUB file.\n\n```\n% pdfinfo /tmp/test.pdf | grep Pages\nPages:           3\n\n% echo '{\"bookTableOfContent\": [ { \"type\": \"imagePdf\", \"name\": \"Test\", \"imagePdf\": \"/tmp/test.pdf\", \"workDir\": \"/tmp/workDir-test.pdf\", \"imagePdfSaveFormat\": \"jpg\" , \"imagePdfSaveQuality\": 100 } ]}' | epub-image-helper --bookConfig @-\n{\n    \"status\": false,\n    \"input\": {\n        \"output\": \"/tmp/test.epub\",\n        \"bookConfig\": \"@-\",\n        \"bookCover\": \"\",\n        \"bookId\": \"438e9899-eafc-42ef-bc21-c0134c4f82f4\",\n        \"bookTitle\": \"Unknown\",\n        \"bookAuthor\": \"Unknown\",\n        \"epubcheck\": false,\n        \"imageDir\": [],\n        \"pickFirstImageToBeBookCover\": false,\n        \"debug\": false,\n        \"bookTableOfContent\": [\n            {\n                \"type\": \"imagePdf\",\n                \"name\": \"Test\",\n                \"imagePdf\": \"/tmp/test.pdf\",\n                \"workDir\": \"/tmp/workDir-test.pdf\",\n                \"imagePdfSaveFormat\": \"jpg\",\n                \"imagePdfSaveQuality\": 100\n            }\n        ],\n        \"imageFormatConversionTable\": {},\n        \"stdin\": \"{\\\"bookTableOfContent\\\": [ { \\\"type\\\": \\\"imagePdf\\\", \\\"name\\\": \\\"Test\\\", \\\"imagePdf\\\": \\\"/tmp/test.pdf\\\", \\\"workDir\\\": \\\"/tmp/workDir-test.pdf\\\", \\\"imagePdfSaveFormat\\\": \\\"jpg\\\" , \\\"imagePdfSaveQuality\\\": 100 } ]}\\n\"\n    },\n    \"output\": {\n        \"path\": null,\n        \"size\": 0,\n        \"sizeReadable\": null,\n        \"imageCount\": 0,\n        \"timeCost\": [\n            2.9087066650390625e-05,\n            3.0279159545898438e-05\n        ]\n    },\n    \"error\": [\n        {\n            \"status\": false,\n            \"error\": [\n                \"type=\\\"imagePdf\\\" error, \\\"workDir\\\" not exists: index=0, item={'type': 'imagePdf', 'name': 'Test', 'imagePdf': '/tmp/test.pdf', 'workDir': '/tmp/workDir-test.pdf', 'imagePdfSaveFormat': 'jpg', 'imagePdfSaveQuality': 100}\"\n            ],\n            \"input\": [\n                {\n                    \"type\": \"imagePdf\",\n                    \"name\": \"Test\",\n                    \"imagePdf\": \"/tmp/test.pdf\",\n                    \"workDir\": \"/tmp/workDir-test.pdf\",\n                    \"imagePdfSaveFormat\": \"jpg\",\n                    \"imagePdfSaveQuality\": 100\n                }\n            ],\n            \"output\": [],\n            \"totalImage\": 0,\n            \"timeCost\": []\n        }\n    ],\n    \"version\": \"1.0.0\"\n}\n\n% mkdir /tmp/workDir-test.pdf\n\n% echo '{\"bookTableOfContent\": [ { \"type\": \"imagePdf\", \"name\": \"Test\", \"imagePdf\": \"/tmp/test.pdf\", \"workDir\": \"/tmp/workDir-test.pdf\", \"imagePdfSaveFormat\": \"jpg\" , \"imagePdfSaveQuality\": 100 } ]}' | epub-image-helper --bookConfig @-\n{\n    \"status\": true,\n    \"input\": {\n        \"output\": \"/tmp/test.epub\",\n        \"bookConfig\": \"@-\",\n        \"bookCover\": \"\",\n        \"bookId\": \"1e788bee-4f66-49f5-bce3-c412a7a4a348\",\n        \"bookTitle\": \"Unknown\",\n        \"bookAuthor\": \"Unknown\",\n        \"epubcheck\": false,\n        \"imageDir\": [],\n        \"pickFirstImageToBeBookCover\": false,\n        \"debug\": false,\n        \"bookTableOfContent\": [\n            {\n                \"type\": \"imagePdf\",\n                \"name\": \"Test\",\n                \"imagePdf\": \"/tmp/test.pdf\",\n                \"workDir\": \"/tmp/workDir-test.pdf\",\n                \"imagePdfSaveFormat\": \"jpg\",\n                \"imagePdfSaveQuality\": 100\n            }\n        ],\n        \"imageFormatConversionTable\": {},\n        \"stdin\": \"{\\\"bookTableOfContent\\\": [ { \\\"type\\\": \\\"imagePdf\\\", \\\"name\\\": \\\"Test\\\", \\\"imagePdf\\\": \\\"/tmp/test.pdf\\\", \\\"workDir\\\": \\\"/tmp/workDir-test.pdf\\\", \\\"imagePdfSaveFormat\\\": \\\"jpg\\\" , \\\"imagePdfSaveQuality\\\": 100 } ]}\\n\"\n    },\n    \"output\": {\n        \"path\": \"/tmp/test.epub\",\n        \"size\": 361006,\n        \"sizeReadable\": \"352.54 KB\",\n        \"imageCount\": 0,\n        \"timeCost\": [\n            3.0994415283203125e-05,\n            0.035225868225097656,\n            0.013682126998901367\n        ]\n    },\n    \"error\": [],\n    \"version\": \"1.0.0\"\n}\n\n% unzip -l /tmp/test.epub \nArchive:  /tmp/test.epub\n  Length      Date    Time    Name\n---------  ---------- -----   ----\n       20  12-17-2023 13:37   mimetype\n      251  12-17-2023 13:37   META-INF/container.xml\n     1802  12-17-2023 13:37   EPUB/content.opf\n       55  12-17-2023 13:37   EPUB/default.css\n   128903  12-17-2023 13:37   EPUB/img-1-000002.jpg\n      608  12-17-2023 13:37   EPUB/xhtml-1-000003.xhtml\n    88590  12-17-2023 13:37   EPUB/img-1-000004.jpg\n      608  12-17-2023 13:37   EPUB/xhtml-1-000005.xhtml\n   142203  12-17-2023 13:37   EPUB/img-1-000006.jpg\n      609  12-17-2023 13:37   EPUB/xhtml-1-000007.xhtml\n      411  12-17-2023 13:37   EPUB/toc.ncx\n      333  12-17-2023 13:37   EPUB/nav.xhtml\n---------                     -------\n   364393                     12 files\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "This tool allows you to easily convert specified photos and images into EPUB e-book format, making it accessible for family and friends. It can be used to create monthly or yearly photo collections for children and transform travel photos into e-books.",
    "version": "1.0.6",
    "project_urls": {
        "Download": "https://pypi.org/project/epub-image-helper/",
        "Homepage": "https://github.com/changyy/epub-image-helper"
    },
    "split_keywords": [
        "python",
        "epub",
        "image",
        "photo",
        "album",
        "pdf"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "06a6dd860b0a1a3ddd0a33be02566d8c632778b3cafc85371db014dff91cb22c",
                "md5": "cf51d5703c48d75fac5e3e20b1988c7c",
                "sha256": "772a3864e826091b2ffad1e3759cfec6417c2c8a08983e958bd9e0cd5243218e"
            },
            "downloads": -1,
            "filename": "epub_image_helper-1.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cf51d5703c48d75fac5e3e20b1988c7c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 16234,
            "upload_time": "2024-01-07T14:26:16",
            "upload_time_iso_8601": "2024-01-07T14:26:16.985924Z",
            "url": "https://files.pythonhosted.org/packages/06/a6/dd860b0a1a3ddd0a33be02566d8c632778b3cafc85371db014dff91cb22c/epub_image_helper-1.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4456091f74863f20950e21a932b87e727613270e07a44e4406adebf62b084ba8",
                "md5": "e78c57ce1ccab463281e0b3d4f080f5d",
                "sha256": "f396126cd9325cd3c4dc20f39bcd44aa800852782a1c141f84657bcaee2d8d14"
            },
            "downloads": -1,
            "filename": "epub-image-helper-1.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "e78c57ce1ccab463281e0b3d4f080f5d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 18594,
            "upload_time": "2024-01-07T14:26:18",
            "upload_time_iso_8601": "2024-01-07T14:26:18.345569Z",
            "url": "https://files.pythonhosted.org/packages/44/56/091f74863f20950e21a932b87e727613270e07a44e4406adebf62b084ba8/epub-image-helper-1.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-07 14:26:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "changyy",
    "github_project": "epub-image-helper",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "epub-image-helper"
}
        
Elapsed time: 0.40755s