1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! Image previews: decode a JPEG, PNG, GIF or WebP (animations included),
//! crop it by gravity or focal point, add a border, round its corners, change
//! its opacity, rotate it, flatten it onto a background, and encode it as
//! JPEG, PNG, GIF, WebP or AVIF.
//!
//! ```
//! use utopia_image::{Gravity, Image, OutputFormat};
//!
//! let jpeg = std::fs::read("../../../packages/image/tests/resources/resize/100x100.jpg")?;
//! let mut image = Image::new(&jpeg)?;
//! image.crop(64, 64, Gravity::Center, None)?.set_border_radius(8)?;
//! let png = image.output(OutputFormat::Png, 90)?;
//! assert_eq!(&png[1..4], b"PNG");
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! ```php
//! use Utopia\Image\Image;
//!
//! $image = new Image(file_get_contents('/usr/src/code/packages/image/tests/resources/resize/100x100.jpg'));
//! $image->crop(64, 64)->setBorderRadius(8);
//! echo substr($image->output('png', 90), 1, 3), "\n"; // PNG
//! ```
//!
//! All the work is CPU-bound: in async code run it on the blocking pool
//! (`utopia_async::spawn_blocking`), never on a runtime thread.
//!
//! The codecs are pure Rust by default. Next to ImageMagick, which the PHP
//! library wraps, that means: WebP is written lossless (no pure-Rust lossy VP8
//! encoder exists), AVIF is written but not read, and HEIC is neither read
//! nor written. Two features add those through the C libraries ImageMagick
//! itself uses: `libwebp` writes lossy WebP at the requested quality, and
//! `libheif` reads AVIF and HEIC, writes AVIF as ImageMagick does, and writes
//! HEIC where the system's libheif has an HEVC encoder (Appwrite's PHP image
//! has none, so HEIC output fails there in PHP too). The pure-Rust AVIF
//! encoder is the default `ravif` feature; a process that forks, such as a
//! PHP extension under Swoole, leaves it out and writes AVIF through libheif. Pixels match ImageMagick's up to resampling and encoder
//! differences; sizes, frames, delays and formats match exactly.
//!
//! PHP → Rust:
//!
//! | PHP (`Utopia\Image`) | Rust (`utopia_image`) |
//! |---|---|
//! | `Canvas`: `new Canvas($data, $limits)`, `new Canvas(new Blank(...))` | [`Canvas`]: [`Canvas::decode`], [`Canvas::blank`] |
//! | `$canvas->width`, `->height`, `->orientation`, `->format` | [`Canvas::width`], [`Canvas::height`], [`Canvas::orientation`], [`Canvas::format`] |
//! | `apply(Transform)` | [`Canvas::apply`] with [`Transform`] |
//! | `draw(Path\|Text)` | [`Canvas::draw`] with [`Drawing`] |
//! | `encode(Format, ?int $quality)` | [`Canvas::encode`] with [`OutputFormat`] |
//! | `Limits` | [`Limits`] |
//! | `Gravity`, `Point` | [`Gravity`], [`FocalPoint`] |
//! | `Font::has($character)` | [`has_glyph`] |
//! | colour strings (`ImagickPixel`) | [`Color`] |
//! | `Exception\ImageException` and its `UnsupportedFormatException`, `CorruptImageException` and `LimitExceededException`; `InvalidArgumentException`, `DivisionByZeroError` | [`Error`] |
pub use crate;
pub use crateColor;
pub use cratehas_glyph;
pub use crate;
pub use crateFormat;
pub use crateImage;
pub use crate;
/// The getting started guide (`guide.md`), compiled and run with the doctests.
;