pub enum Format {
Jpeg,
Png,
Gif,
Webp,
Avif,
Heic,
}Expand description
A raster format Image::new accepts, identified
from the file signature, so only decoders for these formats ever see the
data.
use utopia_image::Format;
assert_eq!(Format::detect(b"\x89PNG\r\n\x1a\n")?, Format::Png);
assert_eq!(Format::Png.value(), "PNG");
assert!(Format::detect(b"P3\n1 1\n255\n").is_err());use Utopia\Image\Format;
echo Format::detect("\x89PNG\r\n\x1A\n")->value, "\n"; // PNG
try {
Format::detect("P3\n1 1\n255\n");
} catch (\Utopia\Image\Exception\UnsupportedFormatException $e) {
echo $e->getMessage(), "\n";
}PHP: Utopia\Image\Format (a string-backed enum).
Variants§
Jpeg
PHP: Format::Jpeg (JPEG).
Png
PHP: Format::Png (PNG).
Gif
PHP: Format::Gif (GIF).
Webp
PHP: Format::Webp (WEBP).
Avif
PHP: Format::Avif (AVIF).
Heic
PHP: Format::Heic (HEIC).
Implementations§
Source§impl Format
impl Format
Sourcepub fn value(self) -> &'static str
pub fn value(self) -> &'static str
The enum’s backing value, ImageMagick’s name for the format (JPEG,
PNG, GIF, WEBP, AVIF, HEIC).
PHP: $format->value.
Sourcepub fn detect(data: &[u8]) -> Result<Format>
pub fn detect(data: &[u8]) -> Result<Format>
The format the data’s signature announces: JPEG, PNG, GIF87a/89a, a RIFF WebP, or an ISO base media file whose file type box lists an AVIF brand (AVIF) or a HEIF brand (HEIC), among its first 4096 bytes.
Fails with Error::UnsupportedFormat for anything else.
PHP: Format::detect($data).
Trait Implementations§
impl Copy for Format
impl Eq for Format
impl StructuralPartialEq for Format
Auto Trait Implementations§
impl Forget for Format
impl Freeze for Format
impl Move for Format
impl RefUnwindSafe for Format
impl Send for Format
impl Sync for Format
impl Unpin for Format
impl UnsafeUnpin for Format
impl UnwindSafe for Format
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more