Metadata-Version: 2.1
Name: FicImageScript
Version: 1.0.1
Summary: FicImage is an application designed to enhance the reading experience of FicHub epubs.
Home-page: https://github.com/Jemeni11/FicImage
Author: Emmanuel C. Jemeni
Author-email: "Emmanuel C. Jemeni" <jemenichinonso11@gmail.com>
License: MIT License
        
        Copyright (c) 2023 Emmanuel C. Jemeni
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/Jemeni11/FicImage
Project-URL: Bug Tracker, https://github.com/Jemeni11/FicImage/issues
Keywords: fanfiction,fichub,ficimage,image
Classifier: Development Status :: 5 - Production/Stable
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Internet :: WWW/HTTP
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: beautifulsoup4 (==4.12.2)
Requires-Dist: certifi (==2022.12.7)
Requires-Dist: charset-normalizer (==3.1.0)
Requires-Dist: EbookLib (==0.18)
Requires-Dist: idna (==3.4)
Requires-Dist: lxml (==4.9.2)
Requires-Dist: Pillow (==9.5.0)
Requires-Dist: requests (==2.29.0)
Requires-Dist: six (==1.16.0)
Requires-Dist: soupsieve (==2.4.1)
Requires-Dist: urllib3 (==1.26.15)

# FicImage/FicImageScript

## Introduction
FicImage is an application designed to enhance the reading experience of FicHub epubs. With FicImage, users can easily add missing images to their FicHub epubs, bringing the stories to life with vibrant visuals. This user-friendly tool allows readers to fully immerse themselves in their favorite fan fiction stories and enjoy them in a whole new way.

## How to Use

### Installation with PIP
1. Install FicImage using `pip install FicImageScript`.
2.  After installation, run the program using `ficimage path/to/epub -c path/to/ficimage/json` 
where `path/to/epub` is the path to the **FicHub epub** you want to add 
images to and `path/to/ficimage/json` is the path to a file called **ficimage.json** . 
ficimage.json lets you configure FicImage. See more [below](#configuration).


```shell
(virt) nonso@HPEnvy:~/Documents/Code$ ficimage -h
usage: ficimage [-h] [-c CONFIG_FILE_PATH] [-d] path_to_epub

Update a FicHub epub file with images.

positional arguments:
  path_to_epub          The path to the FicHub epub file.

optional arguments:
  -h, --help            show this help message and exit
  -c CONFIG_FILE_PATH, --config_file_path CONFIG_FILE_PATH
                        The path to the ficimage.json file.
  -d, --debug           Enable debug mode.

```

### Image Support

[FicHub](https://fichub.net/) creates EPUB 3.3 files, which means that FicImage only save images 
in the following file format:
- JPEG
- PNG
- GIF
- WEBP
- SVG

See the [Core Media Types Section of the EPUB Version 3.3 Specification](https://www.w3.org/TR/epub-33/#sec-core-media-types) for more information.

While FicImage can save SVG images, it can not compress them because SVGs are not supported by Pillow.

FicImage uses [Pillow](https://pillow.readthedocs.io/en/stable/index.html) for image manipulation and conversion. 

By default, FicImage will try and save all non-animated images as JPEGs.

The only animated images that FicImage will save are GIFs and WEBPs.

FicImage does little to no processing on GIFs and WEBPs images. 
This is to avoid breaking the animation.

If FicImage can not download an image, it leaves the image url 
paragraph the same way it met it.

To configure image support, you will need to create a file called `ficimage.json`. 
See the section below for more information.


### Configuration
FicImage comes with a configuration file that allows you to customize the program to your liking.

The configuration file is in the [JSON file format](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON) 
and contains the following options:


- `compress_images`: A boolean that tells FicImage whether to compress images. 
    This is only supported for `jpeg` and `png` images.
- `default_image_format`: A string that tells FicImage what default format to convert and save images in. This is only supported for `jpeg` and `png` images.
- `max_image_size`: An integer that tells FicImage the maximum size of an image in bytes. 
    If an image is larger than this value, FicImage will compress it.


FicImage checks for a configuration file in the given directory path. If no directory 
path is given, FicImage checks the current directory and then the Operating System's 
home directory.

If it does not find one, it uses the following defaults:
    
```json
{
    "compress_images": true,
    "default_image_format": "JPEG",
    "max_image_size": 100000
}
```

> Note: The `compress_images` key is a boolean and can only be `true` or `false`. 
> Booleans in JSON are written in lowercase.

> Note: If the `default_image_format` key does not exist, FicImage will default to `jpeg`.
> The two image formats are `jpeg` and `png`. 
> The `default_image_format` key is case-insensitive.

> Note: The `compress_images` key tells FicImage to compress images. 
> This is only supported for `jpeg` and `png` images.
> This also goes hand-in-hand with the `max_image_size` key. 
> If the `compress_images` key is `true` but there's no `max_image_size` key,
> FicImage will compress the image to a size less than 1MB (1000000 bytes). 
> If the `max_image_size` key is present, FicImage will compress the image
> to a size less than the value of the `max_image_size` key. 
> The `max_image_size` key is in bytes.

> If `compress_images` is `false`, FicImage will ignore the `max_image_size` key.

> Warning: Compressing images might make the image quality worse.

> Warning: `max_image_size` is not a hard limit. FicImage will try to compress the
> image to the size of the `max_image_size` key, but it might
> not be able to compress the image to the exact size of the `max_image_size` key.

> Warning: `max_image_size` should not be too small. 
> For instance, if you set `max_image_size` to 1 000, FicImage will 
> probably not be able to compress the image to 1 000 bytes (1 KB). 
> If you set `max_image_size` to 1 000 000, FicImage will probably be able to
> compress the image to 1 000 000 bytes (1 MB).

> Warning: FicImage will not compress GIFs or WEBPs, that might damage the animation.


## TODO
- [x] Improve logs
- [ ] Conversion to other FicHub supported formats from ePub.
- [ ] More testing 


## Contributing
Fork the repo and get started!


## Links

- Me
  
    [LinkedIn](https://www.linkedin.com/in/emmanuel-jemeni) • [GitHub](https://github.com/Jemeni11) • [Twitter](https://twitter.com/Jemeni11_)

- FicHub

  Without FicHub, this project would (obviously lol) not exist.

  [Website](https://fichub.net/) • [GitHub](https://github.com/FicHub/fichub.net) • [Discord](https://discord.gg/sByBAhX)

  Thanks to [iris](https://github.com/iridescent-beacon) for helping me with this project as well.
