Metadata-Version: 2.5
Name: gif-to-livephoto
Version: 0.1.0
Summary: Python library to convert GIF to iPhone Live Photo (.livp)
Project-URL: Homepage, https://github.com/sherotree/gif-to-livephoto-py
Project-URL: Repository, https://github.com/sherotree/gif-to-livephoto-py
Project-URL: Web Tool, https://www.uwarp.design/gif-to-livephoto
Author-email: Sherotree <sherotree@users.noreply.github.com>
License-Expression: MIT
License-File: LICENSE
Keywords: converter,gif,image,iphone,live-photo,livephoto,video
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Multimedia :: Graphics
Classifier: Topic :: Multimedia :: Video
Requires-Python: >=3.8
Requires-Dist: pillow>=9.0.0
Provides-Extra: dev
Requires-Dist: black>=23.0.0; extra == 'dev'
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
Requires-Dist: pytest>=7.0.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Provides-Extra: test
Requires-Dist: pytest-cov>=4.0.0; extra == 'test'
Requires-Dist: pytest>=7.0.0; extra == 'test'
Description-Content-Type: text/markdown

# gif-to-livephoto

[**GIF to Live Photo**](https://www.uwarp.design/gif-to-livephoto) — free browser tool for converting GIFs to iPhone Live Photos (the reference UI for this library).

Offline Python library for converting animated GIFs into iPhone-usable Live Photo packages (`.livp`).

Package: **`gif-to-livephoto`** on PyPI (`0.1.0`).

## Install

```bash
pip install gif-to-livephoto
```

## System requirements

| Dependency | Required? | Purpose |
| --- | --- | --- |
| **ffmpeg** | **Yes** | Encodes the GIF as H.264 MOV and extracts the JPEG still. Must be on `PATH`. |
| **libheif** | No | Not used. This library writes a **JPEG** still, not HEIC. |

Install ffmpeg:

- macOS: `brew install ffmpeg`
- Ubuntu/Debian: `sudo apt-get install ffmpeg`
- Windows: download from [ffmpeg.org](https://ffmpeg.org/)

If ffmpeg is missing, the library raises `FFmpegNotFoundError` with install hints.

```bash
gif-to-livephoto --check
```

## Quick start

```python
from gif_to_livephoto import convert_gif_to_livephoto

# Write a .livp file
convert_gif_to_livephoto("animation.gif", "output.livp")

# Or get bytes
livp_bytes = convert_gif_to_livephoto("animation.gif")
```

## API

### Convenience function

| Function | Role |
| --- | --- |
| `convert_gif_to_livephoto(gif_source, output_path=None, max_duration=3.0, quality=23)` | Convert a GIF path/bytes/file object to `.livp` (returns bytes when `output_path` is `None`) |

### Class API

| Method | Description |
| --- | --- |
| `GifToLivePhoto(gif_source)` | Load GIF from path, bytes, or file-like object |
| `.convert(output_path=None, max_duration=3.0, quality=23)` | Convert; write file or return bytes |
| `.to_bytes(max_duration=3.0, quality=23)` | Convert and return `.livp` bytes |
| `.get_asset_id()` | UUID pairing still + movie (after convert) |
| `.get_video_preview()` | Raw MOV bytes before metadata injection |
| `.get_still_preview()` | Raw JPEG bytes before metadata injection |

### Errors

| Exception | When |
| --- | --- |
| `FFmpegNotFoundError` | `ffmpeg` is not on `PATH` |
| `FFmpegError` | ffmpeg ran but encoding/extraction failed |

## CLI

```bash
gif-to-livephoto input.gif output.livp
gif-to-livephoto animation.gif          # writes animation.livp
gif-to-livephoto input.gif -d 5.0 -q 20
gif-to-livephoto --check
```

## Live Photo / `.livp` format

A `.livp` file is a **ZIP** (store/no compression) containing a paired still + video:

| Entry | Role |
| --- | --- |
| `IMG_0001.JPG` | Still image. Exif MakerNote (`Apple iOS`) holds the Live Photo **asset identifier** (UUID). Taken from the first GIF frame. |
| `IMG_0001.MOV` | H.264 movie (yuv420p, even dimensions, no audio). QuickTime metadata carries the **same** asset identifier plus a `still-image-time` track that marks the still frame. |

Photos pairs the two files via that shared asset id. Native iPhone captures often use **HEIC + MOV** on disk; this library (and the browser tool) emit **JPEG + MOV** inside `.livp`, which Photos can import. HEIC/libheif support is intentionally out of scope.

Default movie length is capped at **3 seconds** (configurable).

## Examples

### Class usage

```python
from gif_to_livephoto import GifToLivePhoto

converter = GifToLivePhoto("animation.gif")
converter.convert("output.livp", max_duration=3.0, quality=23)
print(converter.get_asset_id())
```

### Bytes in / bytes out

```python
from gif_to_livephoto import convert_gif_to_livephoto

with open("animation.gif", "rb") as f:
    gif_data = f.read()

livp_bytes = convert_gif_to_livephoto(gif_data)
with open("output.livp", "wb") as f:
    f.write(livp_bytes)
```

### Handling a missing ffmpeg

```python
from gif_to_livephoto import convert_gif_to_livephoto, FFmpegNotFoundError

try:
    convert_gif_to_livephoto("animation.gif", "output.livp")
except FFmpegNotFoundError as exc:
    print(exc)  # includes install instructions
```

## Tests

```bash
pip install -e ".[test]"
pytest
# or with coverage
pytest --cov=gif_to_livephoto
```

## Development

```bash
pip install -e ".[dev]"
pytest
black src/ tests/
ruff check src/ tests/
```

## License

MIT. See [LICENSE](./LICENSE).
