Spectrum

Spectrum

  • About Spectrum
  • Getting Started
  • GitHub

›Using Spectrum

Intro

  • About Spectrum

Getting Started

  • Getting Started on Android
  • Getting Started on iOS
  • Sample Apps

Concepts

  • Supported Image Flows
  • Supported Image Formats

Using Spectrum

  • Transcoding Images for Upload
  • Resizing Images
  • Cropping Images
  • Rotating Images
  • Encoding Images
  • FAQ

Contributing

  • Project Structure
  • Contributing on Android
  • Contributing on iOS

Encoding Images

An encode requirement must be set when the target image is compressed. An encode requirement has a few parameters:

  • Format: Defines the target format the image should be encoded to. E.g JPEG.
  • Mode: Defines how the image should be encoded. Can be Any, Lossy or Lossless.
  • Quality: The compression quality that should be used. The value must be between 0 and 100. 0 is deemed as unset in which case a default value for the format will be used.

While JPEG can only perform lossy compression in most cases it may be able to perform lossless transcoding. For more info, check the lossless JPEG bullet point.

Code Sample

The following code encodes an image to JPEG with quality 42:

Android

EncodeRequirement encodeRequirement =
    new EncodeRequirement(
        /* format */ EncodedImageFormat.JPEG,
        /* quality */ 42,
        /* mode */ EncodeRequirement.Mode.LOSSY);

// Pass encode requirement to the options

iOS

FSPEncodeRequirement *encodeRequirement =
    [FSPEncodeRequirement encodeRequirementWithFormat:FSPEncodedImageFormat.jpeg
                                                 mode:FSPEncodeRequirementModeLossy
                                              quality:42];
// Pass encode requirement to the options
← Rotating ImagesFAQ →
  • Code Sample
    • Android
    • iOS
Spectrum
Docs
About SpectrumGetting StartedContributing
Community
FacebookTwitter
Legal
Terms of UseData PolicyCookie Policy
More
GitHubStar
Facebook Open Source
Copyright © 2022 Facebook